statesOnScreen static method

List<NyBaseState<StatefulWidget>> statesOnScreen()

Every Nylo state under the page on top of the navigation stack, in the order they nest: the page itself, then the states it builds.

Implementation

static List<NyBaseState> statesOnScreen() {
  final BuildContext? context = _pageContext();
  if (context == null) return const [];

  final List<NyBaseState> found = [];
  void visit(Element element) {
    if (element is StatefulElement) {
      final State<StatefulWidget> state = element.state;
      if (state is NyBaseState && state.mounted) found.add(state);
    }
    element.visitChildren(visit);
  }

  try {
    context.visitChildElements(visit);
  } catch (_) {
    // The tree is locked (a build is in flight); report what was reached.
  }
  return found;
}