Describe the bug
Calling Provider.of<not nullable T> when not mounted triggers a codepath that attempts to throw an error but throws a less good error instead; here:
if (inheritedElement == null && null is! T) {
throw ProviderNotFoundException(T, context.widget.runtimeType);
}
which throws accessing context.widget.
Expected behavior
A better error message could be provided by checking context.isMounted before trying to access widget.
Describe the bug
Calling
Provider.of<not nullable T>when not mounted triggers a codepath that attempts to throw an error but throws a less good error instead; here:which throws accessing
context.widget.Expected behavior
A better error message could be provided by checking
context.isMountedbefore trying to accesswidget.