Fluttering Your Way to Success: The Ultimate Roadmap for Beginner Flutter Developers! (Part 2)

LOKESH KUMAR
4 min readAug 2, 2023

--

Working of State Management

Hello Everyone, I am back with the Part 2 of my series Roadmap for Flutter Developer, this series is gonna be a long one so be prepared for a roller-coaster ride with lots of bumps, mind-blasting details, curious questions and all…. If you haven’t checked my previous article, you can check here. If you would have followed my previous article you would be aware I have asked few questions, so lets jump into it first.

1. What is State?

In simple terms, state is something that refers to the data that we store in a widget which will be used to determine how the UI is displayed or how the app behaves. Consider it as a memory(Special type of variable) which is stored inside the widget, after every re-render, the data in the state variables will be persist but any other variables will get re-initialise. E.g In the below image, we are trying to simply implement a counter app. When we click on the Plus or Minus button it simply has the logic to increase or decrease the count, but from where it is getting the current count and even after we press the buttons from where it will get the updated count value. This data is stored in the State

Roadmap for flutter:- An example on how the state management works

2. What’s the importance of it (State)? :-

In the above example we can see that we used the state to store the counter information ie the current count. If we don’t have the current count data in state and we have created a variable which we use to store the count value and we hvae initialised with 0, everytime we click on the buttons its always gonna show only 1.

3. Why do we needed a State in the UI development?

To enables apps to handle user interactions, update the UI based on changing data, create animations, handle asynchronous operations, and manage the overall application state. By effectively managing state, developers can provide a seamless and engaging user experience.

4. If state is of any importance then why Stateless widgets are there which don’t have the state?

We have seen above what state helps us to achieve, but for an application there are certain parts which don’t need to be dynamic they can be a simple list of static data. A stateless widget simply renders the UI. We should be identifying the parts of the screen which will be static and make them a stateless widget.

5. Can widgets work even without state?

Yes widgets will work whether it’s a stateless or stateful widget. If you are thinking that stateful widgets needed state then you are wrong. You can create a stateful widget without even a state variable. The basic job of a widget is to render the data, it’s up to you if you want to add state management or not. Depending on the scenario you can use a widget with State Management capabilities and use a Stateful widget or else simply use stateless widget. If there is no state management, then its best to have a stateless widget

6. Why there is no state in Stateless Widgets ?

Statesless widgets were meant to be only to render the static data which won’t be depending on updating dynamically. The part of the screen which dont have to be updated, where no interactions needs to be shown. Stateless widgets were used to improve the performance of the app. Suppose if all the widgets in a screen are all statefull widgets, so if a parent updates all its descendant widgets will also get re-render.

7. Why Stateless widgets are called as dumb widgets?

Because they won’t have the mechanism to update the screen based on any condition/interaction. They were simply meant to render the data.

While working on this article, I realised I can write a lot about the state management but dont wanted to make it boring, so this is the least info I can add up. If you wanted more details shootout in the comments, will be happy to create another article only for state management. Thank you reading the article, I hope you enjoyed it.

--

--

No responses yet