仅在第一次保存对象列表时出现此错误是否有意义?当我将另一个对象添加到列表中时,相同的代码运行没有错误。有没有我遗漏的小技巧?
<块引用>E/flutter (6026): [错误:flutter/lib/ui/ui_dart_state.cc(186)]
未处理的异常:将对象转换为可编码对象失败:
'Proje' E/flutter 实例(6026):#0
_JsonStringifier.writeObject (dart:convert/json.dart:688:7) E/flutter (6026): #1 _JsonStringifier.writeList
(dart:convert/json.dart:736:7) E/flutter (6026): #2
_JsonStringifier.writeJsonValue (dart:convert/json.dart:718:7) E/flutter (6026): #3 _JsonStringifier.writeObject
(dart:convert/json.dart:679:9) E/flutter (6026): #4
_JsonStringifier.writeMap (dart:convert/json.dart:769:7) E/flutter (6026): #5 _JsonStringifier.writeJsonValue
(dart:convert/json.dart:724:21) E/flutter (6026): #6
_JsonStringifier.writeObject (dart:convert/json.dart:679:9) E/flutter (6026): #7 _JsonStringStringifier.printOn
(dart:convert/json.dart:877:17) E/flutter (6026): #8
_JsonStringStringifier.stringify (dart:convert/json.dart:862:5) E/flutter (6026): #9 JsonEncoder.convert
(dart:convert/json.dart:262:30) E/flutter (6026): #10
JsonCodec.encode (dart:convert/json.dart:172:45) E/flutter (6026):
#11 StorageImpl.flush (package:get_storage/src/storage/io.dart:34:37) E/flutter (6026): #12
GetStorage._flush (包:get_storage/src/storage_impl.dart:144:23)
E/flutter(6026):#13 GetQueue._check
(package:get/get_utils/src/queue/get_queue.dart:31:47) E/flutter (
6026):#14 GetQueue.add
(package:get/get_utils/src/queue/get_queue.dart:43:5) E/flutter (
6026):#15 GetStorage._addToQueue
(包:get_storage/src/storage_impl.dart:139:18)E/flutter(6026):
#16 微任务.exec。 (包:get_storage/src/storage_impl.dart:174:17)E/flutter(6026):
#17 _rootRun (dart:async/zone.dart:1346:47) E/flutter (6026): #18 _CustomZone.run (dart:async/zone.dart:1258:19) E/flutter (6026): #19 _CustomZone.runGuarded (dart:async/zone.dart:1162:7) E/flutter (6026):#20 _CustomZone.bindCallbackGuarded。
(dart:async/zone.dart:1202:23) E/flutter (6026): #21 _rootRun
(dart:async/zone.dart:1354:13) E/flutter ( 6026): #22
_CustomZone.run (dart:async/zone.dart:1258:19) E/flutter (6026): #23 _CustomZone.runGuarded (dart:async/zone.dart:1162:7) E/flutter (6026): #24 _CustomZone.bindCallbackGuarded。
(dart:async/zone.dart:1202:23) E/flutter ( 6026): #25
_microtaskLoop (dart:async/schedule_microtask.dart:40:21) E/flutter (6026): #26 _startMicrotaskLoop
(dart:async/schedule_microtask.dart:49:5)
这里是类文件:
class Proje {
int id;
String title;
int tahminiButce;
Proje({this.id, this.title, this.tahminiButce});
factory Proje.fromJson(Map<String, dynamic> json) {
return Proje(
id: int.parse(json["id"]),
title: json["title"],
tahminiButce: int.parse(json["tahminiButce"]),
);
}
//
}
这是运行以保存列表的代码:
void saveOrUpdate() {
var pb = int.tryParse(tec2.text);
var _id = new DateTime.now().millisecondsSinceEpoch;
if (index == null) {
curP.title = tec.text;
curP.tahminiButce = pb == null ? 0 : pb;
curP.id = _id;
pc.projeList.add(curP);
} else {
curP = pc.projeList[index];
curP.title = tec.text;
curP.tahminiButce = pb == null ? 0 : int.parse(tec2.text);
pc.projeList[index] = curP;
}
Get.back();
}
提前致谢。