findWidget<T extends Widget> method

T? findWidget<T extends Widget>()

Returns the Widget of the nearest Page the is an instance of the given type T.

Implementation

T? findWidget<T extends Widget>() {
  for (var pageWrapper in _pageStack.reversed) {
    final page = pageWrapper.pageOrNull;

    if (page is MaterialPage && page.child is T) {
      return page.child as T;
    }

    if (page is CupertinoPage && page.child is T) {
      return page.child as T;
    }

    if (page is DialogPage && page.child is T) {
      return page.child as T;
    }
  }

  return null;
}