| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import 'package:mmkv/mmkv.dart';
- class KVUtil {
- KVUtil._();
- static MMKV? _mmkv;
- static init() async {
- if (_mmkv != null) {
- return;
- }
- await MMKV.initialize();
- _mmkv = MMKV.defaultMMKV();
- }
- static void putString(String key, String? value) {
- _getMMKV().encodeString(key, value);
- }
- static String? getString(String key, String? defaultValue) {
- return _getMMKV().decodeString(key) ?? defaultValue;
- }
- static void putInt(String key, int value) {
- _getMMKV().encodeInt(key, value);
- }
- static int getInt(String key, int defaultValue) {
- return _getMMKV().decodeInt(key, defaultValue: defaultValue);
- }
- static void putBool(String key, bool value) {
- _getMMKV().encodeBool(key, value);
- }
- static bool getBool(String key, bool defaultValue) {
- return _getMMKV().decodeBool(key, defaultValue: defaultValue);
- }
- static void putDouble(String key, double value) {
- _getMMKV().encodeDouble(key, value);
- }
- static double getDouble(String key, double defaultValue) {
- return _getMMKV().decodeDouble(key, defaultValue: defaultValue);
- }
- static MMKV _getMMKV() {
- _mmkv ??= MMKV.defaultMMKV();
- return _mmkv!;
- }
- }
|