Widgets are simple UI building blocks in Flutter. The views in flutter are totally based on Widgets. They describe how the view should look and function according to there states. As the state of the widget changes, it rebuilds the whole render tree again.
Types of Widgets
So, while working on your view, You create mainly two types of layouts. One which stays the same and does not change and the other one which can be changed according to user interactions. Flutter provides two types of widgets for these two types of views.
- StatelessWidgets
- StatefullWidgets
StatelessWidgets
There are some views in your application that does not change just like a title bar, you don’t want anyone to change it. These type of static views are build using StatelessWidgets in Flutter. As they do not change after the create there are no states in these widgets.
1 2 3 4 5 6 7 |
class YourWidget extends StatelessWidget{ @override Widget build(BuildContext context){ return Widgets; } } |
StatefullWidgets
On the other hand, there are views that change according to user interaction just like Checkbox or a RadioButton. These are used to create dynamic views. They can be changed even after the create so they have states in them.
1 2 3 4 5 6 7 8 9 10 |
class YourWidget extends StatefulWidget{ MyWidget({Key key}) : super(key:key); @override _YourWidget createState() => new _YourWidget(); } class _YourWidget extends State<MyWidget>{ Widget build(BuildContext context){ return Widgets; } } |