Flutter state management architecture that I adore

Md Sadab Wasim
Aesthetic coders
Published in
3 min readJul 31, 2021

The simple architecture that saves me a ton of time every day

Photo by Balázs Kétyi on Unsplash

Finally, It’s time to write an article about architecture, I’ve been working with flutter since its alpha release and one thing that never goes away is the discussion about architecture in the flutter community. And I think it’s healthy to do the discussion on this topic, so here’s my take on architecture.

What do I need from an architecture?

  1. Simplicity to understand:- I prefer architecture that is quite simple to understand and has a very low learning curve, so any new dev can grasp it quickly and start doing what matters.
  2. Total separation of business logic:- In flutter as we know, UI and business logic got mixed up very frequently and this can later cause problems and it becomes quite cumbersome to maintain this type of project.
  3. Effortless testing:- Testing the codebase is as important as code, we need an architecture that lets us do straightforward testing.

Quest for excellence

Photo by Ranah Malberg on Unsplash

I had only these 3 demands from the architecture, I have seen Bloc, Redux. Popular architecture like Bloc and Redux has simply a high learning curve and a lot of boilerplate code to set it up, it’ll take time to grasp all the concepts before we can implement and start to use these architectures.

I found Stacked

Stacked architecture is created by Dane Mackier it is an MVVM-like architecture that fulfills all of my three needs.

Simplicity to understand:- We can literally read an article about it (like this one) and start working with it.

Separation of business logic:- For separation stacked goes one step ahead of other architectures, as we all know navigation, dialogs, snack bar, bottom sheets are a big part of any flutter application and one thing that is needed in all of this is the build context, so even we separate our business logic with UI code, we have to navigate, show dialogs/bars/sheets from UI side or pass the context, this also makes it harder to test business logic that includes these things as well.

Effortless testing:- Testing is a breeze in this architecture, all you need is to read this article and you’re good to go for unit testing or even do TDD.

Apart from these things we also got multiple packages for making stacked architecture more amazing, we got stacked themes, stacked hooks, stacked implementation of firebase auth & crashlytics, and many more. If you want to dive into it take a look at its GitHub repo and filledstacks website.

Thanks for sharing your time with me.

Photo by Ian Schneider on Unsplash

--

--