Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading error message if not mounted #813

Open
davidmorgan opened this issue Apr 13, 2023 · 0 comments
Open

Misleading error message if not mounted #813

davidmorgan opened this issue Apr 13, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@davidmorgan
Copy link
Contributor

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.

@davidmorgan davidmorgan added bug Something isn't working needs triage labels Apr 13, 2023
@rrousselGit rrousselGit added enhancement New feature or request and removed bug Something isn't working needs triage labels Apr 13, 2023
@rrousselGit rrousselGit self-assigned this May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants