fluffychat/lib/utils/famedlysdk_store.dart

44 lines
1011 B
Dart
Raw Normal View History

2021-10-26 18:50:34 +02:00
import 'dart:core';
import 'package:shared_preferences/shared_preferences.dart';
2020-05-13 15:58:59 +02:00
class Store {
SharedPreferences? _prefs;
2020-01-01 19:10:13 +01:00
2020-10-25 16:59:55 +01:00
Future<void> _setupLocalStorage() async {
_prefs ??= await SharedPreferences.getInstance();
2020-10-25 16:59:55 +01:00
}
2022-01-29 12:35:03 +01:00
Future<String?> getItem(String key) async {
await _setupLocalStorage();
return _prefs!.getString(key);
2020-01-26 12:17:54 +01:00
}
2022-01-29 12:35:03 +01:00
Future<bool> getItemBool(String key, [bool? defaultValue]) async {
await _setupLocalStorage();
return _prefs!.getBool(key) ?? defaultValue ?? true;
}
2022-01-29 12:35:03 +01:00
Future<void> setItem(String key, String? value) async {
await _setupLocalStorage();
if (value == null) {
await _prefs!.remove(key);
return;
2021-02-03 16:30:23 +01:00
}
await _prefs!.setString(key, value);
return;
2020-01-26 12:17:54 +01:00
}
Future<void> setItemBool(String key, bool value) async {
await _setupLocalStorage();
await _prefs!.setBool(key, value);
return;
}
2020-10-25 16:59:55 +01:00
Future<void> deleteItem(String key) async {
await _setupLocalStorage();
await _prefs!.remove(key);
return;
2020-03-29 12:06:25 +02:00
}
2020-01-01 19:10:13 +01:00
}