Redeem Now
Read More
Read now

Widgets States in Flutter

Save

In this blog we will learn about Widgets States in Flutter

Before going to know about widget states in Flutter let first know something about widget in flutter.

In flutter we use widget to make ui. To build any app in flutter we start it with widget.
It is the building block of flutter application.
We can compare widget with view in android, but the widget is more powerful then view.

Widgets are arranged in parent child tree like structure. The entire widget tree structure forms a layout or screen of app.

Flutter has a rich set off in-built widgets. Apart from this we can also create
own widgets according to need.

Types Of  Widgets

We can divide flutter widgets in two type.

1. Stateless  Widgets
2. Stateful  Widgets

What is state?

The State is information that can read synchronously when the widget is build and might change during their lifetime of the widget.
A information of properties of a widget can be determine from a state.

Stateless Widget:

We are all aware from immutable property means that remains unchanged.

Stateless widgets have immutable property.
They don’t change their state throughout the entire lifetime of widgets or  Stateless widgets can’t change their state when app is running.
We can also say that widgets can’t be redraw while app is running.

For example- Icon and a  text.

If widget doesn’t changes  then it is stateless widgets.

For example

Result:

stateless_widgets
stateless widgets

Stateful Widgets

If a widget changes their behaviour througout their lifetime then it is stateful widgets.

Stateful widgets are dynamic widgets means that they are keep changes their state.

Staetful widgets can re-render or redraw when their state  changes.

They can be updated during runtime  ow while app is running based on user action or data change.

A stateful widget is implemented by two classes: a subclass of StatefulWidget and a subclass of State.

For Example: Checkbox, Radio Button

Let’s take below example in which button color gets changes and count value gets increased by one on every time button clicked.

 

Result :

stateful widget-2
Stateful widget

 

stateful widget

 

 

 

 

 

 

 

Want to know more about states of widgets in flutter click here.

 

Conclusion :

In this blog, we learn about states of widgets in flutter.

Hope ! this will help you in finding what you are looking for.

Thanks For Reading

 

 

 

 

 

 

 

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close