-
-
Notifications
You must be signed in to change notification settings - Fork 956
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
Critical Bug: ref.invalidate() Calls The Notifier Class Build Method Before It Disposes When There Are No Listeners #3760
Comments
It's inconvenient, but I'm not sure about the critical part For now, one workaround is to wrap your "ref.invalidate(p)" into a "ref.exists(p)". |
@rrousselGit thanks for your response, so I should do it like this right?
|
Yes |
thanks, also I mentioned its critical because this could lead to a redundant API call which leads to extra network and financial cost as well as unexpected behavior for example in my case users didn't receive notification for the first message they received because when get messages is called the message notifications gets reset. |
It'll definitely need to be fixed. But considering there's an easy workaround and that it's likely a bit rare, I think it can easily wait a bit :) |
Okay also I would be happy to contribute and try to fix it if possible, as I invalidate many family providers from notifiers in my app and writing if condition for each one could be easily forgotten xD |
Sure, if you feel comfortable doing so! Make sure to test it :) |
Describe the bug
I have a chat screen that watches a family provider that retrieves the messages using the chat Id as a family parameter, when the user receives a message notification I try to invalidate the messages provider from the notifications notifier class, if the chat screen has never been opened before which means there are no listeners the build method of the messages notifier class gets called and a redundant Api call is made to the server to retrieve the messages is made before the provider gets disposed, I have debugged and found out that this problem only occurs when we invalidate a family provider with a parameter from another notifier class and you can Reproduce this bug using the code below you will find out that the first time you click on the invalidate provider button before you open the chat screen the build method of the get messages will be called and getting messages will be printed then provider is disposed will be printed after, but if you opened the chat screen before you click on the invalidate provider then you clicked on invalidate provider the normal behavior will occur.
To Reproduce
** get_messages_notifier.dart **
** notifications_notifier.dart **
** chat_screen.dart **
** main.dart **
Expected behavior
I expect the family provider to be disposed without calling the build method before its disposed for the first time.
The text was updated successfully, but these errors were encountered: