You may laugh, but that probably happens more than we’d like to admit.

And with Flutter, that’s not entirely inconceivable in that with Flutter and Flutter’s way of handling composing UIs. You have to handle data flowing through your app, changing state & widgets interacting with other widgets. Getting this wrong at the very beginning is a very costly mistake to make.

With this blog, you’ll be armed with the tools that you need to be able to make an effective choice at the very beginning. So get ready!

Content :

Pragmatic Way of Managing State in Flutter

State Management

Journey through different approaches in state management

Demo Application

Different Flutter State Management Techniques

Resources


Pragmatic Ways of Managing State in Flutter

✅ Understandable / readable / maintainable

✅ Testing

✅ Performance

  1. Understandable/readable/maintainable — Your UI and your app is going to evolve over time. Therefore, the way you manage the state needs to evolve with it. It needs to be flexible and malleable, so you don’t end up with a spaghetti mess, as you iterate on your UI.
  2. Testing — test state when you want to see its effect on UI and vice versa.
  3. **Performance **— A means by which you can build in the state that will give you good performance, but you always need to be aware of the edge cases.

State Management

If I have a widget, and I want to change its state from somewhere outside of that widget, either from another widget, or from the network, or a system call.

Journey through Approaches in State Management

UI is a function of State


Demo Application

So let’s build a very simple app. It shows the pie chart, and there is a slider, All we want to do is change the state of the pie chart in response to something happening in the slider.

If we look at the very simplified widget tree,we have, basically, only three widgets —

  1. Homepage
  2. MyChart
  3. MySlider

And my slider wants to change the state of my chart.

So we do something that we call in any declarative framework lifting state up. So we lift state up using — my schedule

As soon as slider change —

  • Instead of going to my chart directly, it goes through my schedule. It asks for my schedule and tells it,
hey, you know what? I was tapped, and this value changed
  • My schedule is responsible for notifying its listener. So it notifies my chart,
hey, something changed, and my chart redraws
  • It then goes down to my slider as well and says,
hey, this thing actually changed, and then it changed to my slider

#dart #state-management #android #apps #flutter

Provider State Management
1.50 GEEK