I have a custom CircularProgressIndicator widget wrapped inside the Padding widget. I want to use this custom widget say 100 times inside build method of another (main) widget.
To avoid repetition in code I have assigned it to top level class variable, and then referenced it in wherever I needed.
Apart from code readability and preventing repetition,
will this also improve overall performance of my "main" widget?
Why those two advices:
- Widgets created from classes can be optimized by the flutter framework among other benefits.
- const Objects are created at compile time and for the same configuration the same object is returned.
Say you have your widget constructor like above, anywhere you use this
CustomCircularProgressIndicator the same instance of the widget will be used.
Those aren’t all the optimizations that can be done but they are a good start. For more optimizations like scoping your UI rebuilds see this great answer
Answered By – croxx5f
Answer Checked By – Dawn Plyler (BugsFixing Volunteer)