getFieldsGroupEntriesByPrefix<K, V> method
List<MapEntry<K, V?>>
getFieldsGroupEntriesByPrefix<
K, V>( - String groupPrefix, {
- Map<String, String?>? fields,
- String keyDelimiter = '_',
- String keyPart(
- String key
)?,
- K keyAs(
- String key
)?,
- V? valueAs(
- String key
)?,
- bool filter(
- K key,
- V? value
)?,
})
Implementation
List<MapEntry<K, V?>> getFieldsGroupEntriesByPrefix<K, V>(
String groupPrefix, {
Map<String, String?>? fields,
String keyDelimiter = '_',
String Function(String key)? keyPart,
K Function(String key)? keyAs,
V? Function(String key)? valueAs,
bool Function(K key, V? value)? filter,
}) {
keyPart ??= (k) => k.split(keyDelimiter).last;
keyAs ??= _parserFor<K>();
valueAs ??= _parserForNullable<V>();
fields ??= getFields();
var entries =
fields.entries.where((e) => e.key.startsWith(groupPrefix)).map((e) {
var key = keyPart!(e.key);
var value = e.value ?? '';
var k = keyAs!(key);
var v = valueAs!(value);
return k != null ? MapEntry(k, v) : null;
}).nonNulls;
if (filter != null) {
entries = entries.where((e) => filter(e.key, e.value));
}
return entries.toList();
}