在初始化工作管理器并创建任一任务后,如果我们在任务执行中使用任何插件,则无法识别并抛出错误,如下所示 MissingPluginException(在通道 lyokone/location 上找不到方法 getLocation 的实现)
实际代码:
Workmanager.executeTask((task, inputData) async {
Location locationObject = Location();
locationObject.getLocation();
print(locationObject);
return Future.value(true);
}
Run Code Online (Sandbox Code Playgroud)
基本上,工作管理器任务中使用的任何其他插件似乎都无法识别。
我错过了什么,我需要重新注册我的所有插件吗?
I/flutter (16120): Location permission has error
I/flutter (16120): MissingPluginException(No implementation found for method serviceEnabled on channel lyokone/location)
在python中我会写:
{a:0 for a in range(5)}
Run Code Online (Sandbox Code Playgroud)
要得到
{0: 0, 1: 0, 2: 0, 3: 0, 4: 0}
Run Code Online (Sandbox Code Playgroud)
我怎样才能在 Dart 中实现同样的目标?
到目前为止,我有这个:
{0: 0, 1: 0, 2: 0, 3: 0, 4: 0}
Run Code Online (Sandbox Code Playgroud)
但这会生成地图列表[{0: 0}, {1: 0}, {2: 0}, {3: 0}, {4: 0}],
虽然我想要一张简单的地图
我有一段serde代码可以实现我想要的功能,但我不喜欢它的实现方式。我正在寻求帮助以了解如何改进它。
use std::any::Any;\n\ntrait Model: std::fmt::Debug + Any {\n fn as_any(&self) -> &dyn Any;\n}\n\nimpl Model for Generator {\n fn as_any(&self) -> &dyn Any {\n self\n }\n}\nimpl Model for Connector {\n fn as_any(&self) -> &dyn Any {\n self\n }\n}\n\n#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]\npub struct Generator {\n id: String,\n #[serde(rename = "sourceID")]\n source_id: String,\n}\n\n#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]\npub struct Connector {\n id: String,\n #[serde(rename = "sourceID")]\n source_id: String,\n}\n\n#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]\n#[serde(tag = "type")]\nenum AllModels {\n Generator(Generator),\n Connector(Connector),\n}\n\nfn main() {\n let …Run Code Online (Sandbox Code Playgroud)