As we all know the flutter app consists of widgets only, these are broadly classified into two types:
- Stateless Widget
- Stateful Widget
Stateless widgets are the widgets that don’t change i.e. they are immutable. Its appearance and properties remain unchanged throughout the lifetime of the widget. In simple words, Stateless widgets cannot change their state during the runtime of the app, which means the widgets cannot be redrawn while the app is in action.
Examples: Icon, IconButton, and Text are examples of stateless widgets.
To create a Stateless widget, we have to override the build() method as implemented in the code below.
Stateful Widgets are the ones that change its properties during run-time. They are dynamic i.e., they are mutable and can be drawn multiple times within its lifetime. It can change its appearance in response to events triggered by user interactions or when it receives data.
Examples : Checkbox, Radio Button, Slider, InkWell, Form, and TextField are examples of Stateful widgets.
To create a Stateful widget, we have to override the createState() method, which returns the state of the widget.
Differences Between Stateless and Stateful Widget:
- Stateless Widgets are static widgets.
- They do not depend on any data change or any behavior change.
- Stateless Widgets do not have a state, they will be rendered once and will not update themselves, but will only be updated when external data changes.
- For Example: Text, Icon, RaisedButton are Stateless Widgets.
- Stateful Widgets are dynamic widgets.
- They can be updated during runtime based on user action or data change.
- Stateful Widgets have an internal state and can re-render if the input data changes or if Widget’s state changes.
- For Example: Checkbox, Radio Button, Slider are Stateful Widgets
- Flutter - Stateful vs Stateless Widgets
- Wrap Widget in Flutter
- Raised Button widget in Flutter
- PageView Widget in Flutter
- FlatButton Widget in Flutter
- BottomNavigationBar Widget in Flutter
- ClipRRect Widget in Flutter
- Drawer Widget in Flutter
- ClipRect Widget in Flutter
- Opacity Widget in Flutter
- RotatedBox Widget in Flutter
- RichText Widget in Flutter
- TextSpan Widget in Flutter
- Align Widget in Flutter
- ClipOval widget in Flutter
- Flutter - AppBar Widget
- Flutter - Expanded Widget
- Flutter - SilverAppBar Widget
- Flutter - OctoImage Widget
- Flutter - Tooltip Widget
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.