Closed BenjiFarquhar closed 8 months ago
That looks normal to me. The provider wasn't listened so got disposed. Reading it again after it was disposed recomputes it.
I was unaware this was expected. I tried to do lazy loading of providers by watching them in a switch statement in the build method. But I must watch them upfront to prevent them from recomputing.
Cheers.
Describe the bug When I use a conditional
ref.watch
, the watched provider is disposed of and rebuilt every time theref.watch
runs. Watching it without a conditional correctly only builds the provider once.To Reproduce, run this code
Expected behavior When tapping the button repeatedly, it should only print "rebuilding provider one" and "rebuilding provider two" once each.
Actual behavior It prints them many times after many button taps.
When we change build to this it works as expected:
Versions:
flutter_riverpod: ^2.4.9 riverpod_generator: ^2.3.9 riverpod_annotation: ^2.3.3 build_runner: ^2.4.6