-
-
Notifications
You must be signed in to change notification settings - Fork 972
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
Right place for ref.listen() in ConsumerStatefulWidget #915
Comments
Place it at the beginning of the build method. It won't force your widget to rebuild if the provider updates its state. It just executes the callback you pass into it. |
It add a new listener each time when build metod is called.
…On Fri, Nov 12, 2021, 2:37 AM Daniel Lampl ***@***.***> wrote:
Place it at the beginning of the build method. It won't force your widget
to rebuild if the provider updates its state. It just executes the callback
you pass into it.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#915 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AT2OE2SRTHM4KPFT62IKDEDULQWCBANCNFSM5H2YWBPQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
@rrousselGit this should probably get mentioned in the documentation. What do you think? |
Sorry for pinging, I just checked the dartDoc for listen and it explains everything. |
If you want to listen provider changes in initState you can use ref.listenManual method with fireImmediately flag |
Ah ok, so I guess for simple use cases like this, Thanks a lot! |
This time, the "ref" isn't passed as parameter of the build method, but is rather a property of the ConsumerState object:
But when I use ref.listen() in initState() it throws the following error :-
ref.listen can only be used in build method of ConsumerState
The question is that if I cannot use ref.listen() in init state then where I should place it in the class.
The text was updated successfully, but these errors were encountered: