I have a simple question. In Flutter docs it is explained build
method can be called many times by framework and it is recomended that we should only return widgets through the build
method. But even we return only widgets, isn't it causing some performance issues? If build
method is called 20 times in a second, does not it mean widgets will be rendered 20 times and should not it be slow? If Flutter framework optimizes rendering widgets, how?
Can you please reference some detailed docs or answers for that?
CodePudding user response:
This is a really good question. The Flutter team has put together this really useful video on YouTube that explains this perfectly and in details. Essentially you need to understand the difference between the Widget tree and the element tree. Every widget inside your widget tree is backed by something called an element, and this element is what Flutter actually uses to draw "things" on the screen. The widgets are the visual representation of the elements from the programmer's perspective while the elements are the actual visual representation of the widgets on the screen. The optimizations are done at the element tree level which you usually don't get to work with directly.
CodePudding user response:
Check out that video, there is a lot of useful information here