【发布时间】:2019-09-23 18:30:18
【问题描述】:
如何将 JSON 数组保存到 SharedPreferences 中?
我在下面尝试了一些类似这样的代码,但出现了一些错误:
[错误:flutter/lib/ui/ui_dart_state.cc(148)] 未处理的异常:类型 “文本”不是“字符串”类型的子类型
for (var x = 0; x < dynamicwidget.length - 1; x++) {
_listOrder={
"id_product": dataJSON[x]["product_id"],
"order_count": dynamicwidget[x].controller.text,
};
}
String json = jsonEncode(_listOrder);
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString(categoryname, json);
【问题讨论】:
-
用dynamicwidget[x].controller.text.toString()替换这个dynamicwidget[x].controller.text
-
感谢您的回答,但仍然无法正常工作
-
我认为问题只出在这一行
-
而不是像这样将 order_count 值保存在变量中,然后在此处分配它
标签: arrays json flutter dart sharedpreferences