HiveAdapter constructor
HiveAdapter(
- TypeAdapterRegistry typeAdapterRegistry, {
- String? boxName,
- bool enableEncryption = false,
- String? encryptionKey,
- EncryptionOptions? encryptionOptions,
Creates a new instance of HiveAdapter.
The boxName
parameter is used to specify the name of the Hive box to use.
If no boxName
is provided, a default box name of 'data_cache_x' will be used.
If enableEncryption
is true, encryptionOptions
must be provided.
Throws an ArgumentError if encryption is enabled but no options are provided.
Implementation
HiveAdapter(
this.typeAdapterRegistry, {
String? boxName,
this.enableEncryption = false,
String? encryptionKey,
EncryptionOptions? encryptionOptions,
}) : _boxName = boxName ?? 'data_cache_x' {
if (enableEncryption) {
if (encryptionOptions != null) {
_encryptionOptions = encryptionOptions;
} else if (encryptionKey != null) {
// For backward compatibility
_encryptionOptions = EncryptionOptions(
algorithm: EncryptionAlgorithm.aes256,
key: encryptionKey,
);
} else {
throw ArgumentError(
'Encryption options or key must be provided when encryption is enabled');
}
_encryption = Encryption(
algorithm: _encryptionOptions!.algorithm,
encryptionKey: _encryptionOptions.key,
);
} else {
_encryptionOptions = null;
}
}