HivezBox<K, T> constructor
HivezBox<K, T> (})
Creates a new HivezBox instance for strongly-typed, non-lazy, non-isolated Hive box access.
This constructor initializes a Hive box that operates on the main Dart thread, providing fast, synchronous access to the underlying data store. It is suitable for scenarios where you want direct, high-performance access to your data without the overhead of isolates or lazy loading.
The name parameter specifies the unique name of the box. The optional parameters
allow you to further configure the box:
encryptionCipher: An optionalHiveCipherto transparently encrypt and decrypt all data stored in the box. Use this for secure, at-rest encryption.crashRecovery: Iftrue, enables Hive's crash recovery mechanism to help prevent data corruption in the event of unexpected shutdowns or crashes. Defaults tofalse.path: An optional custom file system path where the box data will be stored. If not specified, the default Hive storage directory is used.collection: An optional collection name to namespace the box within a logical group. This is useful for organizing related boxes or for multi-tenant applications.logger: An optional logger for capturing diagnostic and error information. This can be used to integrate with your application's logging infrastructure for better observability.
Example:
final box = HivezBox<String, MyModel>(
'myBox',
encryptionCipher: MyCipher(),
crashRecovery: true,
path: '/custom/path',
collection: 'user_data',
logger: myLogger,
);
await box.ensureInitialized();
Implementation
HivezBox(
super.name, {
super.encryptionCipher,
super.crashRecovery,
super.path,
super.collection,
super.logger,
}) : super(type: BoxType.regular);