I have a List<Content>
and would like to filter by the properties of a field that is a List.
Content
class Content {
// ...
final List<Tag> tags;
}
Tag
class Tag {
// ...
final String name;
final String slug;
}
Coming from Angular I use
map(data => data.filter(a => a.tags.some(t => t.slug.includes(this.slug)))),
to filter by the slug property of Tag.
However this is now Dart, Flutter and rxdart. I have so far:
applicationBloc.contentOutput.map(
(contents) => contents.where(
(item) => item.tags == widget.slug).toList()
)
contentOutput is a BehaviorSubject's stream.
Essentially I have a few 1000 items and would like to display only content with a certain tag.
How do I filter by a property of a List of objects' properties that is a List in Flutter/Dart?
Use something like:
var foo = <Content>[];
var filtered = foo
.where((content) => content.tags.any((tag) => tag.slug == 'bingo'))
.toList();
Replace the tag.slug == whatever
predicate with whatever test you need.