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

How to catch error used after being disposed? #3935

Open
stephane-archer opened this issue Jan 16, 2025 · 7 comments
Open

How to catch error used after being disposed? #3935

stephane-archer opened this issue Jan 16, 2025 · 7 comments
Assignees
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@stephane-archer
Copy link
Contributor

Image

How can I catch these errors in my code to display them on the screen as error messages for my user?

FlutterError (A LutPreviewImagesChangeNotifier was used after being disposed.
Once you have called dispose() on a LutPreviewImagesChangeNotifier, it can no longer be used.)
@stephane-archer stephane-archer added documentation Improvements or additions to documentation needs triage labels Jan 16, 2025
@rrousselGit
Copy link
Owner

Hard to say without some context. You didn't share much about what's happening here :)

@rrousselGit rrousselGit added question Further information is requested and removed needs triage labels Jan 16, 2025
@stephane-archer
Copy link
Contributor Author

@rrousselGit Sorry I didn't realize I didn't give you enough context.

I try to catch Notifier was used after being disposed.

here is some context on why it happened here:

onClick: () {
var a = ref.read(aProvider.notifier);
var b = ref.read(bProvider.notifier);
a.state = null;
b.state = null; <- but bProvider has recently been change to watch for `aProvider` so this code was working correctly but now b.state uses a notifier after disposed.
}

from the screenshot I shared, I don't see b.state = null; in the call stack, so it seems like the exception was thrown later for some unknown reason (maybe because of async code?). I expected that Riverpod throw that exception but is it?

@zhxst
Copy link

zhxst commented Jan 17, 2025

Do you use ref.watch(aProvider) and ref.watch(bProvider) in the widget build method ?
This usually happens with AutoDisposeNotifier, when you forget to watch the provider, they will be disposed immediately after you call ref.read().

@stephane-archer
Copy link
Contributor Author

This is not an AutoDisposeNotifier but both are ChangeNotifier

@rrousselGit
Copy link
Owner

Sounds like you're talking about this: #3354

@stephane-archer
Copy link
Contributor Author

@rrousselGit it looks similar. I tried to understand the status of it. From my understanding, this will be fixed in the next major release. Is it already fixed in the dev branch?

@rrousselGit
Copy link
Owner

No. Honnestly I'm not sure how to go about it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants