小编Geo*_*rab的帖子

Flutter MethodChannel嵌套值:'List <dynamic>'不是'FutureOr <List <Map <String,double >>>'类型的子类型

我正在编写一个Flutter插件,该插件List<Map<String, double>>从“平台”特定端发送地图列表()。在平台特定方面,我正在使用默认消息编解码器发送这些对象。

// (example: Android side)

List<Map<String, Double>> out = new ArrayList<>();
... fill the map ...
result.success(out);
Run Code Online (Sandbox Code Playgroud)

我在Dart端收到以下这些值:

static Future<List<Map<String, double>>> getListOfMaps() async {
    var traces = await _channel.invokeMethod('getListOfMaps');
    print(traces); // works
    return traces;
}
Run Code Online (Sandbox Code Playgroud)

打印值会给出正确的值。但是,在函数返回上,type 'List<dynamic>' is not a subtype of type 'FutureOr<List<Map<String, double>>>'在运行时出现以下错误,指示从动态值到特定值的转换Map<String, double>不起作用。

如何在Dart中正确转换来自MethodChannels的嵌套值?

dart flutter

3
推荐指数
1
解决办法
1916
查看次数

标签 统计

dart ×1

flutter ×1