Skip to content

Instantly share code, notes, and snippets.

@danahartweg
Created June 20, 2020 22:39
Show Gist options
  • Save danahartweg/e16197e45d5b9f24c74d7f6a6f833879 to your computer and use it in GitHub Desktop.
Save danahartweg/e16197e45d5b9f24c74d7f6a6f833879 to your computer and use it in GitHub Desktop.
ItemListBloc filterSource - Manage lists with Flutter Bloc
Iterable<I> _filterSource(List<I> items) {
final activeConditions =
(_filterConditionsBloc.state as ConditionsInitialized).activeConditions;
if (activeConditions.isEmpty) {
return items;
}
// If any active condition matches we can immediately return that item.
return items.where((item) => activeConditions.any((conditionKey) {
final conditionKeyValue = splitConditionKey(conditionKey);
return item[conditionKeyValue[0]] == conditionKeyValue[1];
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment