Stateful/stateless widgets
In Chapter 1, What Is Flutter and Why Should I Use It?, we learned that widgets play an important role in Flutter application development. They are the pieces that form the UI; they are the code representation of what is visible to the user.
UIs are rarely static; they change frequently, as you will have experienced when you have used a web page or an application. Although immutable by definition, widgets are not meant to be final – after all, we are dealing with a UI, and a UI will certainly change during the life cycle of any application. That’s why Flutter provides two types of widgets: stateless and stateful.
As you might expect, a stateless widget has no state, whereas a stateful widget holds state and adapts based on that state. This difference impacts the life cycle of the widget, how it is constructed, and how the code is structured. It’s the developer’s responsibility to choose what kind of widget to use in each...