setItem method
Saves item by key
to a storage. Value should be json encodable (json.encode()
is called under the hood).
After item was set to storage, consecutive getItem will return json
representation of this item
if toEncodable
is provided, it is called before setting item to storage
otherwise value.toJson()
is called
Implementation
Future<void> setItem(
String key,
value, [
Object toEncodable(Object nonEncodable)?,
]) async {
var data = toEncodable?.call(value) ?? null;
if (data == null) {
try {
data = value.toJson();
} on NoSuchMethodError catch (_) {
data = value;
}
}
await _dir.setItem(key, data);
return _flush();
}