The best type-safe wrapper over SharedPreferences. ⭐ Why so? -> strongly typed cards for access to storage -> don't think about type, use get|set -> can work with nullable values -> callback based updates
switch (card.type) {
case DataType.bool:
return _prefs.setBool(key, resultValue as bool);
case DataType.int:
return _prefs.setInt(key, resultValue as int);
case DataType.double:
return _prefs.setDouble(key, resultValue as double);
case DataType.string:
return _prefs.setString(key, resultValue as String);
case DataType.stringList:
return _prefs.setStringList(key, (resultValue as List).cast<String>());
}
I like its semantics, it also works great. However, a bad idea popped into my head to optimize this....
There's a section of code like this:
I like its semantics, it also works great. However, a bad idea popped into my head to optimize this....
What if you do something like this:
This already looks nasty semantically + adds an unnecessary lambda function + an unnecessary
!
sign when used. But is there any optimization here?