1 year ago
#237183

stcojo
Using Riverpod for Flutter state, what's better: ConsumerWidget or just a Consumer where needed?
I'm fairly new to Riverpod but it seems that using a ConsumerWidget as the body of a screen is a bad practice because the screen is rebuilt when not needed.
For example:
- the main widget (the screen itself) is a ConsumerWidget
- somewhere in the hierarchy I have a list of clickable buttons, for which I'm watching a ChangeNotifierProvider to update a selected index (only one button can be clicked at a time).
It seems that whenever I click one button to update the index (and change the color of the button), the main widget's Build method is called, along with the items in my list.
However, when using just a Consumer widget inside the itemBuilder method of my ListView, clicking one button no longer triggers the build method of the main widget.
So, is it considered a good practice to just use Consumer widgets where needed?
flutter
build
state
riverpod
rebuild
0 Answers
Your Answer