A stateless widget does not hold any state. It is set up once when the widget is created and used to display the same information without any change in data. For example, it is commonly used to implement UI elements like static text, icons, or simple buttons.
Such widgets construct their UI through the build
method, which is called every time the widget needs to be drawn on the screen. However, since there is no state, the UI once built does not change with user interactions.
In the example below, the CustomWidget
class is implemented by inheriting from StatelessWidget
. This class overrides the build
method to return a container and text. This text maintains the style and content defined at the time of creation, and does not update with state changes.