debugSubWidget method

Widget? debugSubWidget(
  1. BuildContext context
)

If a Substitution was made, returns the widget that made it.

The result could be:

The result is always null in profile & release mode.

Implementation

Widget? debugSubWidget(BuildContext context) {
  Widget? result;
  assert(() {
    final GetAny? scopedGet = GetScope.maybeOf(context, _get);
    if (scopedGet == null) return true;
    final GetScope scope = context.findAncestorStateOfType<_GetScopeState>()!.widget;
    for (final SubAny sub in scope.substitutes) {
      if (sub.ref == _get) {
        result = scope;
        return true;
      }
    }
    final container =
        context.getElementForInheritedWidgetOfExactType<_OverrideContainer>()!
            as _OverrideContainerElement;

    for (final MapEntry(key: context, value: map) in container.clientSubstitutes.entries) {
      for (final ValueRef key in map.keys) {
        if (key == _get) {
          result = context.widget;
          return true;
        }
      }
    }

    throw StateError(
      'The object $_get was substituted with $scopedGet, '
      'but the substitution was not found.\n'
      '$bugReport',
    );
  }());

  return result;
}