I'm having a hard time understanding what an element is in Flutter. From the doc: "An instantiation of a Widget at a particular location in the tree". . . . I guess now I have to ask, what is the tree.
At first, I thought the tree referred to the states of widgets, but StatelessWidget also has createElement, so this doesn't seem the case. Then, I thought that the tree referred to the parent/child relationship, but it is not clear to me. Finally, it sounds like an element is sort of like a snapshot of the widget at that particular time and location, but the associated methods don't seem to reflect that. Am I anywhere close?
Flutter creates element for widget(including child widgets) it's displayed on the screen and it has a reference to the widget. Flutter framework creates the element tree which represents the rendered widget on the screen. An Element represents the use of a widget to configure a specific location in the tree. The element can change if the parent widget rebuilds and creates a new widget for this location. Element(mutable property) are created by createElement() method. The framework calls mount method to add the newly created element to the tree at a given slot in a given parent.
For more info, see this documentation
In Flutter widget
is the configuration of the UI, the main class which represents the element or UI displayed on the screen is Element
.
i.e Widget is actually the configuration data of Element and the Widget tree is actually a configuration tree, for the Element tree which is automatically generated whenever we create a widget tree.
More Info here - https://api.flutter.dev/flutter/widgets/Element-class.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With