【发布时间】:2019-10-03 02:58:08
【问题描述】:
我写了this code 来做这件事。我的 API 完全正常工作,没有问题。当我想打印Product class 字段之一时,我的代码正在工作,但是当我想将我的所有 json 文件解析为 Map 并将其添加到列表时它不起作用。这是错误:
Unhandled exception:
NoSuchMethodError: The method 'add' was called on null.
Receiver: null
Tried calling: add(Instance of 'Product')
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
#1 ProductNetwork.fetchProduct
package:dart_project/product.dart:62
<asynchronous suspension>
#2 main
package:dart_project/main.dart:5
<asynchronous suspension>
#3 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:300:19)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:171:12)
Exited (255)
我的code有什么问题?
【问题讨论】:
-
请不要使用外部链接来显示您的代码。相反,请edit 将您的代码的minimal reproducible example 包含在问题本身中。
标签: json parsing serialization dart flutter