reopenDatabase method

Future<Database> reopenDatabase(
  1. String localId
)

Reopens a database previously opened with openDatabase, reusing the key already held in the KeyStore — no passphrase required.

Throws StateError if no key is stored for localId (i.e. the database has never been opened on this device, or was Database.leave-d).

Implementation

Future<Database> reopenDatabase(String localId) async {
  if (_databases.containsKey(localId)) return _databases[localId]!;
  await resumePendingRotation(localId);

  final entryKey = '${_config.appId}/$localId';

  final key = await _keyStore.getKey(entryKey);
  if (key == null) {
    throw StateError(
      'No stored key for "$localId"; call openDatabase with a passphrase '
      'first.',
    );
  }
  final cipher = _cipherFactory(key);

  return _finishOpen(localId, entryKey, key, cipher);
}