What is an element in Flutter?

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

enter image description here


Flutter creates a visual tree of Elements, which are like mutable copies of Widgets. You don't normally deal directly with Elements, the framework does.

So (a very simplified version of) your tree might look something like this:

MediaQuery 
-- Theme Data
---- Scaffold
------ AppBar
------ Body
--------- Column
----------- Text
----------- Text
----------- Row
------------- Button
------------- Button
------ FloatingActionButton

Those Texts may well be the same Widget being reused multiple times, but in the tree there are unique Elements.

Tags:

Flutter