hive_wait 1.0.2+2 copy "hive_wait: ^1.0.2+2" to clipboard
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
130
points
9
downloads

Publisher

unverified uploader

Weekly Downloads

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

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

hive, meta

More

Packages that depend on hive_wait