Flutter get_storage本地存储

发布时间 2023-06-05 13:41:12作者: Python喵

倪大头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();