fetchTargetSliverContexts method

List<BuildContext> fetchTargetSliverContexts()
inherited

Fetch target sliver BuildContexts

Implementation

List<BuildContext> fetchTargetSliverContexts() {
  List<BuildContext> ctxs = targetSliverContexts;
  if (ctxs.isEmpty) {
    final sliverListContexts = widget.sliverContexts;
    if (sliverListContexts != null) {
      ctxs = sliverListContexts();
    } else {
      List<BuildContext> _ctxs = [];
      void visitor(Element element) {
        if (isTargetSliverContextType(element.renderObject)) {
          /// Find the target sliver context
          _ctxs.add(element);
          return;
        }
        element.visitChildren(visitor);
      }

      try {
        // https://github.com/LinXunFeng/flutter_scrollview_observer/issues/35
        context.visitChildElements(visitor);
      } catch (e) {
        Log.warning(
          'This widget has been unmounted, so the State no longer has a context (and should be considered defunct). \n'
          'Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active.',
        );
      }

      ctxs = _ctxs;
    }
  }
  return ctxs;
}