hive_wait 1.0.2+2 icon indicating copy to clipboard operation
hive_wait: ^1.0.2+2 copied to clipboard

Wait until the Hive is ready to use before calling the box's methods.

Hive Wait #

Hive Wait provide a Hive repository to calling methods in the box as async.

Wait until the Hive is ready to use before calling the box's methods.

Usage #

  • Wait init Hive
class CoreRepository<E> extends HiveRepository<E> {
  CoreRepository(
    String name, {
    bool? lazy,
    HiveCipher? encryptionCipher,
    KeyComparator? keyComparator,
    CompactionStrategy? compactionStrategy,
    bool? crashRecovery,
    String? boxPath,
    Uint8List? bytes,
  }) : super(
          name,
          lazy: lazy,
          encryptionCipher: encryptionCipher,
          keyComparator: keyComparator,
          compactionStrategy: compactionStrategy,
          crashRecovery: crashRecovery,
          boxPath: boxPath,
          bytes: bytes,
        );

  @override
  Future<BoxBase<E>> init([HiveInterface? hive]) async {
    await Hive.initFlutter();
    // TODO: Register adapter
    return await super.init(Hive);
  }
}
  • Using with get_it
class CoreRepository<E> extends HiveRepository<E> {
  CoreRepository(
    String name, {
    bool? lazy,
  }) : super(name, lazy: lazy);

  @override
  Future<BoxBase<E>> init([HiveInterface? hive]) async {
    await getIt.allReady();
    hive = await getIt.getAsync<HiveInterface>();
    return await super.init(hive);
  }
}

// TODO: register a singleton with get_it
class PropertyRepository extends CoreRepository<Property> {
  PropertyRepository() : super('property');
}
  • Get data
getUser() async {
  var userRepository = CoreRepository<User>('user');
  return await userRepository.get(0);
}
0
likes
110
pub points
2%
popularity

Publisher

unverified uploader

Wait until the Hive is ready to use before calling the box's methods.

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

hive, meta

More

Packages that depend on hive_wait