Skip to content

Instantly share code, notes, and snippets.

@utkarsh-UK
Created November 22, 2020 17:43
Show Gist options
  • Save utkarsh-UK/808fb25c0043c39720c6977fad86ebc2 to your computer and use it in GitHub Desktop.
Save utkarsh-UK/808fb25c0043c39720c6977fad86ebc2 to your computer and use it in GitHub Desktop.
Future<void> saveUserToken(String token) async {
try {
//BOX_NAME is any string key for you box name.
final secureKey = Hive.generateSecureKey();
final encryptedBox = await Hive.openBox(BOX_NAME, encryptionKey: secureKey);
await encryptedBox.put('token', token);
//SECURE_STORAGE_KEY is any string key.
await secureStorage.write(
key: SECURE_STORAGE_KEY,
value: json.encode(secureKey),
);
} on Exception catch (e) {
throw CacheException(message: e.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment