debugSubWidget method
If a Substitution was made, returns the widget that made it.
The result could be:
- A GetScope, if the substitution was made there
- A HookWidget that called useSubstitute
- Another widget that used a
Refinstance method such as Ref.sub null, if no substitution was made
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;
}