IPersistStore class abstract
PersistStore Interface to implementation.
You don't have to use try-catch, as it is done by the library.
Examples
SharedPreferences:
class SharedPreferencesImp implements IPersistStore {
late SharedPreferences _sharedPreferences;
@override
Future<void> init() async {
//Initialize the plugging
_sharedPreferences = await SharedPreferences.getInstance();
}
@override
Object? read(String key) {
return _sharedPreferences.getString(key);
}
@override
Future<void> write<T>(String key, T value) async {
await _sharedPreferences.setString(key, value as String);
}
@override
Future<void> delete(String key) async {
await _sharedPreferences.remove(key);
}
@override
Future<void> deleteAll() async {
await _sharedPreferences.clear();
}
}
Hive:
class HiveImp implements IPersistStore {
late Box box;
@override
Future<void> init() async {
await Hive.initFlutter();
box = await Hive.openBox('myBox');
}
@override
Object? read(String key) {
return box.get(key);
}
@override
Future<void> write<T>(String key, T value) async {
await box.put(key, value);
}
@override
Future<void> delete(String key) async {
await box.delete(key);
}
@override
Future<void> deleteAll() async {
await box.clear();
}
}
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
delete(
String key) → Future< void> - Delete
-
deleteAll(
) → Future< void> - Purge localStorage
-
init(
) → Future< void> - Initialize the localStorage service
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
read(
String key) → Object? - Read from localStorage
-
toString(
) → String -
A string representation of this object.
inherited
-
write<
T> (String key, T value) → Future< void> - Write on the localStorage
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
getRepo<
T extends IPersistStore> () → T - get the local storage repository