Flutter. Write your own state management library in 40 lines of code

Yuri Novicow
Easy Flutter
Published in
3 min readJun 2, 2024

--

Disclaimer: actually, 42 without empty lines and lines with only brackets.

Riverpod? Overcomplicated.

Provider? Outdated.

BLoC? Too verbose.

GetX? Controversial and too ubiquitous. (I am, personally, happy with GetX for now).

So, what to do? Write your own. It is, actually, much easier than you may think.

What do we need?

  1. “Provider” class. This is the analog to Flutter’s native ChangeNotifier or GetXController. It holds state(s) and notifies widgets when the state changes.
  2. “Consumer” widget. This is the analog to Provider’s/Riverpod’s Consumer widget or GetBuilder in GetX.
  3. “Locator” class. This class holds a Map of Providers and Consumers that depends on those Providers.
  4. Last but not least. Cool name.

Let’s start from the end. We will call our library…

If you are a member, just continue, otherwise, read the full story here.

EzState.

Super cool.

Now, let’s write Locator class.

class _EzLocator {
static final _EzLocator _instance =…

--

--

Yuri Novicow
Easy Flutter

20 years in software development. Writes about Flutter. Always looks for the most efficient paths. Shares secrets openly.