我正在编写一个Flutter插件,它从平台特定端发送一个 Map 列表( List<Map<String, double>>
) . 在平台特定方面,我使用默认消息编解码器发送这些对象 .
// (example: Android side)
List<Map<String, Double>> out = new ArrayList<>();
... fill the map ...
result.success(out);
我在Dart方面收到如下值:
static Future<List<Map<String, double>>> getListOfMaps() async {
var traces = await _channel.invokeMethod('getListOfMaps');
print(traces); // works
return traces;
}
打印值会给出正确的值 . 但是,在函数返回上,我在运行时收到以下错误 type 'List<dynamic>' is not a subtype of type 'FutureOr<List<Map<String, double>>>'
,表示从动态值到特定 Map<String, double>
的强制转换不起作用 .
如何在Dart中正确地转换来自MethodChannels的嵌套值?
1 回答
正如评论中指出的那样,我必须将具有未知运行时类型的每个值单独地转换为期望的类型 .