saveValueWithKey<T> method
T
is the runTimeType
data which you are trying to save (bool
- String
- double
)
Implementation
Future<bool> saveValueWithKey<T>(String key, T value) async {
_logger.d("SharedPreferences: [Saving data] -> key: $key, value: $value");
if (value is String) {
return _preferences!.setString(key, value);
} else if (value is bool) {
return _preferences!.setBool(key, value);
} else if (value is double) {
return _preferences!.setDouble(key, value);
} else if (value is int) {
return _preferences!.setInt(key, value);
}
throw NotSupportedTypeToSaveException();
}