Widgets in Flutter

Widgets in Flutter

Hey guys, its been a while now I have been learning app development using Flutter 👨‍💻 .
So I would like to give some insight into how Flutter actually works.

INTRODUCTION :

To build any application in Flutter, we must create a widget class, which is the building block of a Flutter application. The whole Flutter application is built using different types of widgets.
These are some of the most basic widgets. First, we have a Text widget and a Button widget. These are some basic UI designing widgets. We also have a Column and Row widget. This widget tells other widgets to arrange themselves vertically or horizontally.🔺Importantly, there's no CSS or styling language, it's just widgets.

Widgets in Flutter are classified into two types: Stateless widgets and Stateful widgets.

1)Stateless widgets
A stateless widget cannot change its state during the runtime of a Flutter application. That means a stateless widget cannot be changed while the app is in action
For that reason, the appearance and properties remain unchanged throughout the lifetime of the widget.
Stateless widgets can be useful when the part of the UI we are describing does not depend on any other widget. Examples of stateless widgets are text, icons, icon buttons, and raised buttons.
Whenever the Stateless widget screen is initialized, the build method is called. After that, the widget will be printed on the screen.

But if we want it to be updated once there is an action, we have to make a stateful widget.

2)Stateful widgets
A stateful widget is used when some part of the UI must change dynamically during runtime. Stateful widgets can redraw themselves multiple times while the app is running.

Stateful widgets are useful when part of the UI changes dynamically. If we create a button widget that updates itself each time a user clicks that button, that is a stateful widget.
setState() is a method that is called within stateful widget classes. This method changes the value of a stateful widget each time it is called.

Conclusion
We’ve covered the differences between stateful and stateless widgets to help you build better Flutter applications.

Here I have created a simple dice app that can display random faces of dice whenever we click on roll dice.
It also has a reset button to start over the game, which will start counting moves from 1 again.
Hope you will like it 😊 .