concept widget tree in category flutter

This is an excerpt from Manning's book Flutter in Action.
Next, Flutter builds all the widgets and constructs the widget tree. By widgets, here I mean the data and configuration that dictate how elements on the screen will look. When it builds a button for the tree, it’s not actually building a blue rectangle with text in it; that’s a later step. Widgets just handle the configuration of elements that will eventually be painted on the screen.
The general goal when developing a UI with Flutter is to compose a ton of widgets together to build the widget tree. A Flutter app is represented by a widget tree, similar to how the DOM on the browser is a tree structure. The widget tree is an actual tree data structure in code built behind the scenes by Flutter, but it’s also a useful way to talk about the structure of your Flutter app. While learning Flutter, whether throughout this book or elsewhere, you’ll encounter the widget tree quite often.
Anytime Flutter is rebuilding, the element’s reference points to the new widget in the exact location in the widget tree of the element’s old reference. When Flutter is deciding what to rebuild and re-render after build is called, an element is going to look at the widget in the exact same place as the previous widget it referenced (see figure 3.18). Then, it’ll decide if the widget is the same (in which case it doesn’t need to do anything), or if the widget has changed, or it’s a different widget altogether (in which case it needs to re-render).
So, when you swap those two buttons, they replace each other in the widget tree, but the element’s reference points to the same location. Each element is going to look at its widget and say, “Has this widget changed? Or is it a new widget altogether?” So, we’d expect the element to see that the widget’s color property has changed, so it should in fact update its reference to the new widget.
A StatefulWidget tracks its own internal state, via an associated state object. A StatelessWidget is “dumb” and is destroyed entirely when Flutter removes it from the widget tree.