grouped method
List<({PrintCategory? category, List<PrintTemplate> templates})>
grouped({
- bool where(
- PrintTemplate template
Templates grouped by category, in category order. Templates whose category does not exist any more are listed under a null key at the end.
Implementation
List<({PrintCategory? category, List<PrintTemplate> templates})> grouped({
bool Function(PrintTemplate template)? where,
}) {
final visible = _templates.where(where ?? (_) => true).toList()
..sort((a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()));
final knownIds = _categories.map((category) => category.id).toSet();
return [
for (final category in categories)
(
category: category,
templates: visible
.where((template) => template.categoryId == category.id)
.toList(),
),
(
category: null,
templates: visible
.where((template) => !knownIds.contains(template.categoryId))
.toList(),
),
];
}