79085789

Date: 2024-10-14 10:38:24
Score: 0.5
Natty:
Report link

Flutter’s approach on the reconstruction of widgets takes this form that within the body, widgets that depend on the observation or sensitiveness on ‘MediaQuery’ for example are the only widgets going for example. Let's see how this goes in detail.

Dependency Tracking:

When a widget needs a certain property of the MediaQuery (such as in Widget2, MediaQuery.viewInsetsOf(context).bottom), Flutter records this as a MediaQuery dependency that specific child widgets will need to build based on their view configuration. The MediaQuery widget (which wraps the app) gives information about the present media state such as screen size, orientation, padding, etc. Thus, since Widget2 directly utilizes this set of information, every time the data related to MediaQuery changes, Flutter queues up Widget2 for a rebuild.

Widget-Specific Rebuilds:

Flutter optimizes the process of rebuilding the widgets. When they are changed, the systems involving the rebuild involve only the views that depend directly on the concrete inherent views closely related to those widgets being changed. As for you, since Widget2 is the only one that depended on the value MediaQuery.viewInsetsOf(context).bottom, it was the only widget that got rebuilt. Widget1 does not access or depend on the MediaQuery member, hence it is not rebuilt.

Efficient Rendering:

This is part of the rendering system of Flutter. In other words, unnecessary reconstruction of widgets is limited. Instead of propagating through the widget tree, only that part of the widget tree that needs to change is changed any way. Since Widget1 does not need to know about the bottom inset, it remains intact

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Vaibhav Yadav