class User{
String userName;
DateTime userDate;
List<UserDetail> detail;
}
class UserDetail{
String adress;
bool isActive;
DateTime dateTime
}
像这样吗?如何使用SharedPreferences保存?
发布于 2020-01-05 02:51:16
共享偏好就像Map<String,String>
一样使用(如果我没记错的话)。所以我要做的就是为你的模型实现toJson和FromJson,将Map
从toJson()转换成字符串,并用一些你以后可以访问的键来存储它。在检索数据时,使用fromJson方法对检索到的字符串进行解码,您将得到一个具有相同值的新对象。
编辑:转换为json和从json转换的最好方法是使用代码生成:https://flutter.dev/docs/development/data-and-backend/json
https://stackoverflow.com/questions/59593052
复制相似问题