initHive method

Future<void> initHive({
  1. String? dir,
})
  • dir 存储路径

Implementation

Future<void> initHive({String? dir}) async {
  if (dir.isNullOrBlank) {
    final root = await Yuro.temporaryDirectory.then((dir) => dir.parent);
    final dbDir = Directory(root.path.join('hive'));
    if (!dbDir.existsSync()) dbDir.createSync(recursive: true);
    dir = dbDir.path;
  }
  final hiveKey = Yuro.sp.getString('hiveKey');
  if (hiveKey == null) {
    _hiveKey = Hive.generateSecureKey();
    await Yuro.sp.setString('hiveKey', _hiveKey.toHex());
  } else {
    _hiveKey = hiveKey.fromHex();
  }
  await Hive.initFlutter(dir);
}