visitStateOrNull<T extends State<StatefulWidget>> method

T? visitStateOrNull<T extends State<StatefulWidget>>({
  1. bool last = false,
  2. bool filter(
    1. T state
    )?,
})

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

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

Implementation

T? visitStateOrNull<T extends State>({
  bool last = false,
  bool Function(T state)? filter,
}) {
  bool filterByT(StatefulElement e) =>
      e.state is T && (filter?.call(e.state as T) ?? true);

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