initDatabase static method

Future initDatabase({
  1. Directory? directory,
  2. String? hiveBoxName = 'local_cache',
  3. HiveCipher? encryptionCipher,
})

Implementation

static Future initDatabase({
  Directory? directory,
  String? hiveBoxName = 'local_cache',
  HiveCipher? encryptionCipher,
}) {
  Future future = Future(() async {
    Directory? appDir = directory;

    try{
      if (RxNetPlatform.isWindows) {
        appDir = appDir??await getApplicationSupportDirectory();
      } else if (RxNetPlatform.isLinux) {
        final home = Platform.environment['HOME'];
        appDir = appDir??Directory(join(home!, '.rxnet_local_cache'));
      } else if(RxNetPlatform.isAndroidOrIOS){
        appDir = appDir??await getTemporaryDirectory();
      } else{
        appDir = appDir??await getApplicationDocumentsDirectory();
      }
    }catch (e){
      appDir = appDir??await getTemporaryDirectory();
    }
    Hive.init(p.join(appDir.path, 'rxnet_local_cache'));
    _box = Hive.openBoxSafe(hiveBoxName!, encryptionCipher: encryptionCipher);
    isDatabaseReady = true;
    for (var callBack in _checkDataBaseListener) {
      callBack.call(isDatabaseReady);
    }
    _checkDataBaseListener.clear();
  });
  return future;
}