Skip to content

Instantly share code, notes, and snippets.

@arnold-parge
Created June 14, 2020 15:12
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 arnold-parge/026e28c8514f5c28d4db07d4ca35aff9 to your computer and use it in GitHub Desktop.
Save arnold-parge/026e28c8514f5c28d4db07d4ca35aff9 to your computer and use it in GitHub Desktop.
Configuration for registering user model in hive database
class AppHiveDb {
AppHiveDb._();
static AppHiveDb instance = AppHiveDb._();
Box<UserModel> userBox;
Box shared;
Future init() async {
var _directory = await getApplicationDocumentsDirectory();
Hive
..init(_directory.path)
// User config start
..registerAdapter(UserModelAdapter())
..registerAdapter(UserDobAdapter())
..registerAdapter(UserIdAdapter())
..registerAdapter(UserLocationAdapter())
..registerAdapter(UserCoordinatesAdapter())
..registerAdapter(UserStreetAdapter())
..registerAdapter(UserTimezoneAdapter())
..registerAdapter(UserLoginAdapter())
..registerAdapter(UserNameAdapter())
..registerAdapter(UserPictureAdapter());
var boxStartTime = DateTime.now().millisecondsSinceEpoch;
userBox = await Hive.openBox<UserModel>('userBox');
var boxEndTime = DateTime.now().millisecondsSinceEpoch;
appWarning(
'Time taken open the user box (hive thing): ${boxEndTime - boxStartTime}ms');
// User config end
// Shared data config start
shared = await Hive.openBox('shared');
// Shared data config end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment