Skip to content

Instantly share code, notes, and snippets.

@JEuler
Last active December 24, 2019 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JEuler/a546a23c982af7ea65454252f6bce9fb to your computer and use it in GitHub Desktop.
Save JEuler/a546a23c982af7ea65454252f6bce9fb to your computer and use it in GitHub Desktop.
/// Implementation of StorageService using Hive Key-Value DB
class StorageServiceImpl implements StorageService {
@override
Future saveUser(User user) async {
final userToSave = DBUser(
user.id,
user.name,
user.avatar);
final usersBox = await Hive.openBox('user');
usersBox.put('current_user', userToSave);
}
@override
Future<DBUser> getUser() async {
final usersBox = await Hive.openBox('user');
final user = usersBox.get('current_user');
return user;
}
@override
void stop() {
Hive.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment