filterBlocks method
List<Block>
filterBlocks({
- List<
BlockTypes> exclude = const [], - List<
BlockTypes> include = const [], - BlockTypes? onlyLeft,
- String? id,
Filter the list of blocks.
Can exclude
or include
blocks of a certain types. Also can onlyLeft
blocks of one type or search blocks by id
.
If all fields are included then all filters are applied as a chain following the next order: exclude
, include
, onlyLeft
, and the id
.
Implementation
List<Block> filterBlocks({
List<BlockTypes> exclude: const [],
List<BlockTypes> include: const [],
BlockTypes? onlyLeft,
String? id,
}) {
List<Block> filetered = <Block>[];
filetered.addAll(_blocks);
if (exclude.isNotEmpty) {
filetered.removeWhere((block) => exclude.contains(block.type));
} else if (include.isNotEmpty) {
filetered.retainWhere((block) => include.contains(block.type));
} else if (onlyLeft != null) {
filetered.retainWhere((element) => element.type == onlyLeft);
} else if (id != null) {
filetered.retainWhere((element) => element.id == id);
}
return filetered;
}