visitWidget<T extends Widget> method
T
visitWidget<T extends Widget>({})
Returns the first T with filter below this BuildContext.
If last is true, then it will return the last Widget found.
Visiting last is O(N), avoid using last = true.
Implementation
T visitWidget<T extends Widget>({
bool last = false,
bool Function(T widget)? filter,
String? assertType,
}) {
final list = <T>[];
final widget = visitWidgetOrNull<T>(
last: last,
filter: (widget) {
list.add(widget);
return filter?.call(widget) ?? true;
},
);
final extra = list.isNotEmpty ? 'Found $list.' : '';
assert(widget != null, 'No ${assertType ?? T} at this context. $extra');
return widget!;
}