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

Consumer using disposed provider on macos #807

Closed
gmparker2000 opened this issue Mar 4, 2023 · 2 comments
Closed

Consumer using disposed provider on macos #807

gmparker2000 opened this issue Mar 4, 2023 · 2 comments

Comments

@gmparker2000
Copy link

When building for macos I have a problem when I resize the window. The provider is being disposed and I get something like this:

  The following assertion was thrown building Consumer<BlahProvider>(dirty, dependencies: 
  [_InheritedProviderScope<BlahProvider?>]):
  A BlahProvider was used after being disposed.

  Once you have called dispose() on a BlahProvider, it can no longer be used.

Any ideas?

@johnxpres
Copy link

johnxpres commented Mar 15, 2023

When building for macos I have a problem when I resize the window. The provider is being disposed and I get something like this:

  The following assertion was thrown building Consumer<BlahProvider>(dirty, dependencies: 
  [_InheritedProviderScope<BlahProvider?>]):
  A BlahProvider was used after being disposed.

  Once you have called dispose() on a BlahProvider, it can no longer be used.

Any ideas?

This error occurs when you try to use a BlahProvider instance after it has been disposed of. When a ChangeNotifierProvider is removed from the widget tree or is no longer needed, its associated ChangeNotifier is disposed of using the dispose method. Once a ChangeNotifier has been disposed of, it can no longer be used, and any attempt to access its properties or call its methods will result in this error.
To fix this error, you should ensure that you are not using a disposed BlahProvider instance. This can be done by checking whether the BuildContext has access to a non-null BlahProvider instance using Provider.of(context, listen: false) or context.read() before using it. If the provider is null or has been disposed of, you should recreate the provider or avoid using it.
Additionally, you can also avoid this error by ensuring that you dispose of the ChangeNotifierProvider instance properly when it is no longer needed, such as when the widget that uses it is removed from the widget tree or when the state that uses it is no longer needed. This can be done by wrapping the widget tree that uses the provider in a Consumer widget, or by manually removing the provider from the widget tree using removeProvider method of the ProviderContainer.

@rrousselGit
Copy link
Owner

Closing as this was answered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants