of static method

bool of(
  1. BuildContext context
)

Tells the visibility state of an element in the tree based off its ancestor Visibility elements.

If there's one or more Visibility widgets in the ancestor tree, this will return true if and only if all of those widgets have visible set to true. If there is no Visibility widget in the ancestor tree of the specified build context, this will return true.

This will register a dependency from the specified context on any Visibility elements in the ancestor tree, such that if any of their visibilities changes, the specified context will be rebuilt.

Implementation

static bool of(BuildContext context) {
  bool isVisible = true;
  BuildContext ancestorContext = context;
  InheritedElement? ancestor = ancestorContext.getElementForInheritedWidgetOfExactType<_VisibilityScope>();
  while (isVisible && ancestor != null) {
    final _VisibilityScope scope = context.dependOnInheritedElement(ancestor) as _VisibilityScope;
    isVisible = scope.isVisible;
    ancestor.visitAncestorElements((Element parent) {
      ancestorContext = parent;
      return false;
    });
    ancestor = ancestorContext.getElementForInheritedWidgetOfExactType<_VisibilityScope>();
  }
  return isVisible;
}