scanKeys method

  1. @override
Future<Stream<String>> scanKeys(
  1. KeyPattern pattern, {
  2. bool includeExpired = false,
  3. OrderByKey? orderBy,
  4. int? limit,
  5. int? skip,
})
override

Stream the keystore keys that match pattern. Backend- portable successor to KeyValueStore.getKeys for callers that want structured filtering rather than building regular expressions.

The return type is Stream<String> (rather than Stream<K>): KeyPattern's fields — sharedBy, sharedWith, namespace, idPrefix — are atKey-shaped, so the result is inherently a stream of atKey strings.

By default, expired or not-yet-born keys are excluded; pass includeExpired: true to surface them.

orderBy controls the result order. null (default) means "the backend's natural order". limit caps the number of keys yielded; skip discards the first N.

The returned Future completes once the backend has accepted the request; the Stream then yields the matching keys.

Implementation

@override
Future<Stream<String>> scanKeys(
  KeyPattern pattern, {
  bool includeExpired = false,
  OrderByKey? orderBy,
  int? limit,
  int? skip,
}) async {
  if (!getBox().isOpen) {
    throw DataStoreException(
        'Failed to scan keys. Hive Keystore is not initialized or opened');
  }

  if (orderBy == null || orderBy == OrderByKey.byKey) {
    return _scanKeysOrdered(
      pattern,
      includeExpired: includeExpired,
      sortByKey: orderBy == OrderByKey.byKey,
      limit: limit,
      skip: skip,
    );
  } else {
    return _scanKeysOrderedByMetadata(
      pattern,
      includeExpired: includeExpired,
      orderBy: orderBy,
      limit: limit,
      skip: skip,
    );
  }
}