whereKeyStartsWithOrFail method

  1. @override
Map<String, dynamic> whereKeyStartsWithOrFail(
  1. String prefix, {
  2. Exception onFail()?,
})

Implementation

@override
Map<String, dynamic> whereKeyStartsWithOrFail(String prefix,
    {Exception Function()? onFail}) {
  final entries = _storage.entries
      .where((element) => element.key.startsWith(prefix))
      .fold(<String, dynamic>{},
          (acc, element) => {...acc, element.key: element.value});

  return entries.isEmpty
      ? onFail != null
          ? throw onFail()
          : throw Exception('No keys found')
      : entries;
}