Minimal #0 - Getting started

 Overview

In this post I'll show you how to quickly get started with Minimal, a minimalistic state management package in the context of an MVN (Model View Notifier) architecture. This is only a very brief intro to get you started. I'll expand each step in details in follow-up posts


State Management in 4 Steps

Adam was on spot when he wrote:

I never really checked the documentation because it’s so simple and easy to use. You don’t need to read everything to start building your app. Just create an immutable class, a state holder, a manager, and use the class in your UI. It’s truly minimal in every sense!
and if you've already some basic experience with other state management solutions, you'll pick this up real fast. In case you don't, or in case you're confused, there are only 4 basic steps you need to follow to start structuring your architecture. I'll summarise them here, but they're also in the README, and the package comes with an example app which showcases the most common use cases.

1 Create an immutable UI state

You can create an immutable state using Dart Mappable, or Freezed, or anything you like












2 Create a notifier to hold your state

The notifier will initiate with an initial state, and it will use notify() to mutate the state













3 Create a manager to access your notifier

Only if you need to autodispose the notifier when it has no more listeners, set autodispose to true





4 Use the notifier from UI

When the user clicks a button, and you need to mutate the state, you can access the notifier through the manager and call a method on it







When the state changes, you want to rebuild your UI passing the notifier to a ListenableBuilder()











To avoid unnecessarily rebuilds, pass only a selection of your state to the ListenableBuilder() using select()










Conclusion

In this post you saw briefly how to get started using Minimal. In the next posts you'll see each step in details.


Comments