如何解决如何为List <Map>添加值
Future<List> go() async {
var returned = await fetchdata();
List<Datum> datas = returned.data;
int tm = returned.data.length;
List<Map> list = new List<Map>(tm);
print(datas[3].menuName);
print(tm);
for (var i = 0; i < tm; i++) {
list[i].putIfAbsent(0,() => datas[i].menuName);
}
return list;
}
我有这段代码,我试图将List<Datum>
的值放在List<Map>
中。但是我收到以下错误:
I/flutter (24996): RICE AND DODO
I/flutter (24996): 13
E/flutter (24996): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'putIfAbsent' was called on null.
E/flutter (24996): Receiver: null
E/flutter (24996): Tried calling: putIfAbsent(0,Closure: () => String)
在这种情况下如何设置正确的值?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。