SqliteAdapter constructor

SqliteAdapter({
  1. String? boxName,
  2. bool enableEncryption = false,
  3. String? encryptionKey,
  4. EncryptionOptions? encryptionOptions,
})

Creates a new instance of SqliteAdapter.

The boxName parameter is used to specify the name of the SQLite database to use. If no boxName is provided, a default 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

SqliteAdapter({
  this.boxName,
  this.enableEncryption = false,
  String? encryptionKey,
  EncryptionOptions? encryptionOptions,
}) {
  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;
  }
}