Peace be upon you
I am researching Flutter's widget lifecycle and stopped at a point which is the this.mounted boolean variable, it does exist directly in the State class, which can only be connected with a StatefulWidget as a subclass and never will/did with a StatelessWidget.
The question is ...
Do all widgets actually contain the
bool this.mountedvariable as some say here in [this accepted answer, this article and this ], or not?
I searched in Flutter and found this mounted variable only in the State class, then I looked further to find a function called mount() inside the Element class.
The StatelessWidget class is connected to the StatelessElement class, which extends from the ComponentElement that inherits directly from the Element class.
I'm really confused right now, maybe I misunderstood this, I need an explanation for this please!, Thank you.
Not sure why that answers says
all widgets. ButNO.Only
State<T>objects are the ones that have agetternamedmounted.This is easy to verify, Just
cmd + clickorctrl + clickon anyStateyou have in your class which will redirect you to a file calledframework.dartwhich is located atflutter -> package -> flutter -> lib -> src -> widgetspath.Search
mountedand this line is the only actual declaration that you will find.And that's part of the
Stateclass' code.