在一个定制插件中,我有一些SWIFT代码,我想返回一组字典,如下所示:
func myCustomFunc(call: FlutterMethodCall, result: @escaping FlutterResult) {
var someArrayOfDicts: [[String: Int]] = []
someArrayOfDicts.append(["fieldA": 12345, "fieldB": 67890])
result(someArrayOfDicts)
}
但是当我.invokeMethod<List<Map<String, int>>>('myCustomFunc')
时,我得到一个错误:_CastError (type 'List<Object>' is not a subtype of type 'List<Map<String, int>>' in type cast)
有关报文传送编解码器的颤动频道文档似乎表明,SWIFT中的Array
和Dictionary
在DART中被接收为List
和Map
。
1条答案
按热度按时间l7wslrjt1#
根据您的报告:
但是当我
.invokeMethod<List<Map<String, int>>>('myCustomFunc')
时,我得到一个错误:_CastError (type 'List<Object>' is not a subtype of type 'List<Map<String, int>>' in type cast)
我建议这样做:
因为您已经知道定义了哪些数据类型。您可以尝试从结果列表中提取数据,然后将其设置为所需的格式。
例如: