write method
Writes a value to secure storage.
The value is converted to a string before storage, and that string is
returned. If value is null, the key is deleted and null is returned.
Example:
// Store a string
await storage.write('user.name', 'John Doe');
// Store a number
await storage.write('app.version', 2.1);
// Store JSON
await storage.write('user.preferences', jsonEncode(prefs));
// Delete by writing null
await storage.write('temp.key', null);
See also:
Implementation
@override
Future<String?> write(String key, dynamic value) async {
if (value == null) {
await delete(key);
return null;
}
final text = value.toString();
await _store.write(key: key, value: text);
return text;
}