【发布时间】:2021-09-27 02:08:20
【问题描述】:
我在代码中使用 Local Storage(shared_preferences: ^2.0.6) 期间发现了这个问题....但是我无法将 api 模型对象存储在本地存储中...我该怎么办?
storeModelInPrefs() async {
http.Response response =
await http.get(Uri.parse('http://18.191.193.64/api/view_categories'));
String encodeData = jsonEncode(response.body);
///Write Data in local Storage
GetStorageUtility.prefs!.write('key', encodeData);
///Read Data from local Storage
String data = GetStorageUtility.prefs!.read('key');
if (data == null) {
print('no data in GetStorage');
} else {
Map<String, dynamic> map = jsonDecode(data);
print(map);
}
}
【问题讨论】:
-
你能展示一下 GetStorageUtility 类吗?
标签: flutter dart local-storage sharedpreferences flutter-test