Last active
November 22, 2020 18:30
-
-
Save utkarsh-UK/f8f3f11d3f97871f37476a6fadecb357 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> cacheUser(UserModel userModel) async { | |
try { | |
final CacheUserModel cacheUser = CacheUserModel( | |
userModel.email, | |
userModel.name, | |
userModel.phone, | |
userModel.role, | |
); | |
//CACHE_BOX_NAME is any string key | |
final userBox = await hive.openBox(CACHE_BOX_NAME); | |
await userBox.put('user', cacheUser); | |
await userBox.close(); | |
} on Exception { | |
throw CacheException(); | |
} | |
} | |
Future<CacheUserModel> getPersistedUser() async { | |
try { | |
final userBox = await hive.openBox(CACHE_BOX_NAME); | |
final CacheUserModel cacheUser = userBox.get('user') as CacheUserModel; | |
await userBox.close(); | |
return cacheUser; | |
} on Exception { | |
throw CacheException(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment