Flutter get_storage本地存储

倪大头IP属地: 山东
0.097字数 84阅读 4,451

之前本地存储用的是shared_preferences,但它的存取都是异步的,现在推荐一个Getx提供的本地存储插件get_storage

dependencies:
  get_storage:
import 'package:get_storage/get_storage.dart';

需要在main函数中init一下

main() async {
  await GetStorage.init();
  runApp(App());
}

然后就可以使用了,使用时创建一个实例对象:

final GetStorage storageBox = GetStorage();

存:

storageBox.write(key, value);

取:

storageBox.read(key);

删除:

storageBox.remove(key);

清空所有字段:

storageBox.erase();
posted @   Python喵  阅读(631)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示