Multiple calls to build method when reading an AutoDisposeNotifier #2436
-
I have been playing around with the new Notifier/AsyncNotifier providers and replacing my old StateProviders. Currently I have some problems with a Notifier class that inherit from AutoDisposeNotifier. Every time I read the NotifierProvider associate to this class the build method is called. For example: My provider with the notifier class
Lets say I have Widget A, with two child widget, B and C.
When the children component are builded the build method inside provider is called, setting the state to 0. Thats mean the build method inside Counter is called 2 time, one per component build. I can increment this value latter clicking on B and C buttons, but when I click on button inside parent widget (Widget A), and read the provider, the build method of Counter notifier is called, setting the state again to 0 and overriding the incremented value. Is only happening when I extend the class from AutoDisposeNotifier, but not when use Notifier. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Anyone know why is happening? is this a bug? Why each time I read an AutoDisposeNotifier triggers the build method? |
Beta Was this translation helpful? Give feedback.
-
Don't use |
Beta Was this translation helpful? Give feedback.
-
ok, but why? |
Beta Was this translation helpful? Give feedback.
Don't use
ref.read
to subscribe for changes inside build. instead, useref.watch
.