getKeys method
Streams the keys, optionally filtered by regex. The returned
Future completes once the backend has accepted the request —
setup failures (store not open, invalid regex) reject the
Future eagerly rather than surfacing mid-stream; the Stream
then yields the matching keys.
Implementation
@override
Future<Stream<String>> getKeys({String? regex}) async {
var keys = <String>[];
// ignore: prefer_typing_uninitialized_variables
var encodedKeys;
if (_getBox().keys.isEmpty) {
return const Stream.empty();
}
// If regular expression is not null or not empty, filter keys on regular expression.
if (regex != null && regex.isNotEmpty) {
encodedKeys = _getBox().keys.where(
(element) => Utf7.decode(element).toString().contains(RegExp(regex)));
} else {
encodedKeys = _getBox().keys.toList();
}
encodedKeys?.forEach((key) => keys.add(Utf7.decode(key)));
return Stream.fromIterable(keys);
}