Are nested Consumers endorsed? #1199
-
I would like to optimize my code when possible. My "bad" code (a bit simplified):
I would like that, whenever the state of p2 or p3 changes, only the badge where p2 or p3 is being watched gets updated (maybe this case with svg pictures is a bit weird, because In general, is it safe to use nested consumers? The outer one contains Code sample:
Or is there a cleaner way to achieve this? Maybe using HooksWidgets? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Actually, in my case p1, p2 and p3 should all watch some global state, therefore I am a bit unsure of my HookWidget suggestion. |
Beta Was this translation helpful? Give feedback.
-
It's fine. Although I'd personally prefer writing slightly more code and extracting every I like to split big widgets early, and it achieves the same effect – on top of maybe allowing const constructors if your widget only depends on providers |
Beta Was this translation helpful? Give feedback.
-
Thank you for your answer! I now have another question: what advantages/guarantees do const constructors of |
Beta Was this translation helpful? Give feedback.
It's fine.
Although I'd personally prefer writing slightly more code and extracting every
Consumer(...)
into a customextends ConsumerWidget
classI like to split big widgets early, and it achieves the same effect – on top of maybe allowing const constructors if your widget only depends on providers