In flutter everything is a widget. Widget is a user interface. Application is the top level widget and UI is built using multiple child widgets. Each widget nests inside its parent and can receive context from the parent. Flutter has platform specific design widgets, MaterialApp for Android and CupertinoApp for iOS. You can understand the widget hierarchy from the diagram below.
The framework introduces two types of widgets:
- Stateless widget
- Stateful widget
The widgets whose properties do not change over time are called stateless widgets. Stateless widgets remain static throughout its lifecycle. The examples of stateless widgets are Text, Container, Row, Column etc..
2) Stateful widget
If the property of the widget changes based on user interaction or other factors then that widget is stateful widget. If the user clicks on a button whose label is date and it opens a calendar widget, after changing date from the calendar, the label of that button needs to be updated with a new date value. The value of date is the state for that button. When the date changes, the button needs to be rebuilt using setState() method.
Stateful widget has two classes: State object and Widget. This widget does not have a build() method. It has createState() method, which returns a class that extends the Flutters State Class. Examples of stateful widgets are TextField, TextFormField, RaisedButton, InkWell, Checkbox etc..