Skip to content

Misleading error message if not mounted #813

Description

@davidmorgan

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions