MOTOSHARE ๐Ÿš—๐Ÿ๏ธ
Turning Idle Vehicles into Shared Rides & Earnings

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Owners earn. Renters ride.
๐Ÿš€ Everyone wins.

Start Your Journey with Motoshare

State management in Flutter

Inย Flutterย everything is aย widget. A widget isย mostlyย the Component on the Screen, likeย Text,ย Image, someย List,ย or even screen. Below is the picture of some of the commonly used widgets

Moreover, widget has its Stateย as well which is actually theย dataย that is being used in building of widget, A text Widget may have String data in the state of to show that String on the screen.

Flutter uses the below equationย in fig(c)ย to render the widget on the application screen. Whereย fย is the build function of the widget, which defines how the widget would look like,ย the stateย is theย current stateย of the widget, andย UIย is the actual output of the widget on the screen.

However, once you define the widget and it is built, then you can not change the widget appear change d). For instance, you can not change the String in Text widget dynamically, sinceย widgets are Immutable, i.e.,ย Unchangeable.

Though widgets areย unchangeableย Fig (d), but widgetโ€™s state areย mutable,ย changeableย Fig (e), these types of widget are calledย Stateful widget,ย and since Flutter is aย declarative Framework, wheneverย the state of widget changes, the widget gets rendered again with the new state.ย So changing the widgetโ€™s state is indirectly same as changing the widget dynamically.

Flutter has two types of widgetsย Statefulย widget, discussed above, andย Statelessย widget.

Stateful widget is the widget whose state is mutable, thus you can change the widget appearance dynamically by changing the state of widget. Changing the widget state fig(f).

setState()

In Stateful widget, whenever there is some change that occurs in the state, we call setState() method, available inside the Stateful widget. Calling setState tells the Framework that the widgetโ€™s state is updated, and the widget should be rebuilt, hence it is rebuilt with the new state, see Fig (f).

Flutter uses the below equation to render widget, and if there is some change in the state of widget, then again it uses the same equation and the same build function, which defines how widget would look like, but with a new state value to draw updated UI on the screen.

On the other hand, Stateless widget is a widget whose state is immutable, thus you can not change the widget appearance dynamically in any way. So, they are used when we have static widget.

State types.

Now if we make a Stateful widget, its state is only available to the widget itself. however, sometimes it is essential to have a common state between different widgets so that different widgets can use the same state data at the same time.

Letโ€™s consider a short scenario. Say, if we are making a cart application in which a user can select products from the application and add them to the cart, and once He completes his shopping, he can navigate to the Checkout screen so that he can know and pay the bill.

Now as you can see in Fig (h), the cart, which is a list of selected products, is in the state of the Cart Screen widget, local to the widget. Now this Cart that is in the state of the Cart Screen widget is not available in the Checkout Screen widget, however, we need a Cart in the Checkout Screen as well for the calculation and making of bills.

To solve this, we lift the state up to a widget which is the ancestor widget of all the widgets that are using that common state fig(i). This technique is called Lifting the state up.

The State which is local to a widget or define in widget itself calledย Ephemeral Stateย and the State that is common to different widgets is calledย Global Stateย orย App State.

So,ย State Managementย is all about managing the state, deciding which widgetโ€™s state needs to be mutable (Stateful widget), and which needs to be immutableย (Stateless Widget).ย Calling setStateย whenever there is a change in the state of widget, and deciding where to put state either in widget itself or in the common ancestor widget.

Thatโ€™s the basics ofย State Managementย that you must learn and implement in order to master the art ofย State Management,ย because every advance state management likeย Providerย ,ย BLoC, orย Redux, all implements, behind the scenes, the same thing, which we have discussed above.

Related Posts

Searching for Free or Paid Legal Advice Near You in India: What to Know

Experiencing a legal crisis or needing formal paperwork reviewed can quickly become overwhelming. Whether you are dealing with a sudden police inquiry, securing a real estate title,…

Read More

Global Dental Tourism: A Comprehensive Guide to Treatments, Costs, and Safe Care Abroad

Introduction In recent years, an increasing number of individuals have looked beyond their local borders to address their dental health needs. This widespread practice, commonly referred to…

Read More

The Definitive Handbook to Exploring and Enjoying Bangaloreโ€™s Dynamic Cultural Scene

Introduction Bangalore, widely celebrated as both the Garden City and the tech capital of India, pulses with an extraordinary creative vitality. Far beyond its shimmering corporate parks…

Read More

Top-Rated Chartered Accountant Near Me for Tax, Audit & Compliance

Introduction Mastering todayโ€™s complex financial and regulatory environment requires far more than basic bookkeeping, demanding expert guidance to avoid costly compliance missteps, manage tax liabilities, and ensure…

Read More

Best Business Software Solutions Reviewed

Introduction Modern organizations rely on digital infrastructure to maintain operational agility, drive revenue growth, and safeguard critical data. Choosing the wrong software stack can lead to fragmented…

Read More

Mastering Autonomous AI: The Ultimate Agentic AI Certification Course

Introduction Artificial intelligence has entered a transformative era, shifting from passive text generation to goal-driven execution through Agentic AIโ€”autonomous systems that can independently reason, plan, invoke tools,…

Read More
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x