shared_store 0.0.1 shared_store: ^0.0.1 copied to clipboard
Native storage solution based on MMKV.
shared_store #
Native storage solution based on MMKV.
Example #
iOS
Android
Usage #
一,Flutter端 #
1.添加依赖:
dependencies:
flutter:
sdk: flutter
shared_store: ^0.01
2.启用SharedStore前,导入shared_store_plugin.dart
对其进行初始化:
import 'package:shared_store/shared_store_plugin.dart';
SharedStorePlugin.initMMKV();
3.根据是否需要添加除内置默认的default
MMKV外的可选的MMKV实例:
String customMMKVId = "testPlugin";
SharedStorePlugin.addMMKV(customMMKVId);
4.在需要存储数据时:
const bool testBool = true;
const int testInt = 123456;
const double testDouble = 3.1415926;
const String testString = 'testStringValue';
String? boolResult = await SharedStorePlugin.storeBool('testBool', testBool);
String? doubleResult = await SharedStorePlugin.storeDouble('testDouble', testDouble);
String? intResult = await SharedStorePlugin.storeInt('testInt', testInt);
String? stringResult = await SharedStorePlugin.storeString('testString', testString);
5.在需要读取数据时:
bool? readBool = await SharedStorePlugin.readBool('testBool');
int? readInt = await SharedStorePlugin.readInt('testInt');
double? readDouble = await SharedStorePlugin.readDouble('testDouble');
String? readString = await SharedStorePlugin.readString('testString');