MemValue simplifies syntax for persistent or stored values like SharedPreferences (or similar packages). This addition provides type safety to ensure loading and storing values of the same type. Meaning, when you define a MemValue of type int, only an int value will be stored. This is useful for ensuring that the value you are retrieving is the type you expect.
Important: You need to provide MemValue with a storage method before using any MemValue.
Check out the example app for a complete demonstration of all MemValue features with an interactive Flutter UI.
var username = MemString('uniqueTag');await username.load();username.value = "Hello World";
print(username.value);Assigning a value to username.value will automatically save the value to storage. To wait for the async operation, use await username.setValue().
- Easy to use syntax.
- Use your perfered storage method.
- 20 Defined types (including custom).
MemChoiceswrapper to ensues only a set of values are storred.MemGroupto load/reset multiple values.
class MyMemStorage extends MemStorage {
Future<String?> read(String tag)async{
// Your code here
}
Future<void> write(String tag, String value)async{
// Your code here
}
Future<void> delete(String tag)async{
// Your code here
}
}var memStorageDelegate = MemStorageDelegate(
read: (tag) async {
// Your code here
},
write: (tag, value) async {
// Your code here
},
delete: (tag) async {
// Your code here
},
);In main, call MemValue.setup to define storage
void main() async {
/* .. .*/
// Setting up MemStorage
MemValue.setStorage(MyMemStorage());
// --OR--
// Setting up MemStorage using delegate
MemValue.setStorage(memStorageDelegate);
/* ... */
runApp(MyApp());
}var username = MemString('uniqueTag');await username.load();Note: you may also define MemGroup to load multiple values like so:
var memValue1 = MemString('uniqueTag1');
var memValue2 = MemString('uniqueTag2');
var memGroup = MemGroup([
memValue1,
memValue2,
]);
await memGroup.loadAll();flutter pub add mem_value
var username = MemString('uniqueTag', initValue: "Hello");Resets value to it's inital value.
await username.reset();Presistant flag avoid resetting value when reset is called. Useful for storing values that should never be reset to inital value.
var username = MemString('uniqueTag', ignoreReset: true);- memValue
- MemDouble
- MemString
- MemBool
- MemList
- MemSet
- MemMap
- MemObject
- MemCustom
- MemChoices
- NmemValue
- NMemDouble
- NMemString
- NMemBool
- NMemList
- NMemSet
- NMemMap
- NMemObject
- NMemCustom
- NMemChoices
Hope you find this package useful. I am open for suggestions and contributions. Please feel free to open an issue or pull request.