setStorageValue method
Set a value in the storage, associated with a key and the logged-in user.
This method first retrieves the current user and then sets the provided value in the storage, associated with the provided key and the user.
key
: The key with which the value will be associated in the storage.value
: The value to be stored.
Returns a Future
that completes when the value has been set.
Example:
await authRequest.setStorageValue('exampleKey', 'exampleValue');
Implementation
Future<void> setStorageValue(String key, dynamic value) async {
try {
// Retrieve the current user.
final currentUser = await getCurrentUser();
// If the user is not null, set the user property in the storage.
if (currentUser != null) {
await CoffeeStorage.setUserProperty(currentUser, key, value);
}
// ignore: empty_catches
} catch (e) { }
}