visiblePylons static method

List<Pylon> visiblePylons(
  1. BuildContext context, {
  2. bool ignoreLocals = false,
})

Returns a list of all visible Pylon widgets in the widget tree, starting from context.

This method traverses up the widget tree and collects all ancestors that are Pylon widgets. If ignoreLocals is true, pylons with local set to true will be excluded.

The context is the starting build context. The ignoreLocals determines whether to ignore pylons with local set to true.

Returns a list of Pylon widgets.

Example:

List<Pylon> visibleProviders = Pylon.visiblePylons(context);

Implementation

static List<Pylon> visiblePylons(BuildContext context,
    {bool ignoreLocals = false}) {
  List<Pylon> providers = [];

  context.visitAncestorElements((element) {
    if (element.widget is Pylon) {
      Pylon p = element.widget as Pylon;

      if (ignoreLocals && p.local) {
        return true;
      }

      if (!providers.any((i) => i.runtimeType == p.runtimeType)) {
        providers.add(p);
      }
    }

    return true;
  });

  return providers;
}