build static method

Future<HydratedStorage> build({
  1. required Directory storageDirectory,
})

Returns an instance of HydratedStorage.

Implementation

static Future<HydratedStorage> build({
  required Directory storageDirectory,
}) {
  return _lock.synchronized(() async {
    if (_instance != null) return _instance!;
    hive = HiveImpl();
    Box<dynamic> box;

    if (storageDirectory == webStorageDirectory) {
      box = await hive.openBox<dynamic>('hydrated_box');
    } else {
      hive.init(storageDirectory.path);
      box = await hive.openBox<dynamic>('hydrated_box');
      await _migrate(storageDirectory, box);
    }

    return _instance = HydratedStorage(box);
  });
}