visitWidgetOrNull<T extends Widget> method

T? visitWidgetOrNull<T extends Widget>({
  1. bool last = false,
  2. bool filter(
    1. T widget
    )?,
})

Returns the first T with filter below this BuildContext, or null.

If last is true, then it will return the last Widget found. Visiting last is O(N), avoid using last = true.

Implementation

T? visitWidgetOrNull<T extends Widget>({
  bool last = false,
  bool Function(T widget)? filter,
}) {
  bool filterByT(Element e) =>
      e.widget is T && (filter?.call(e.widget as T) ?? true);

  return visitElementOrNull(last: last, filter: filterByT)?.widget as T?;
}