Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

a simple yet powerful state management technique for Flutter

states_rebuilder

states_rebuilder is a flutter state management solution that allows for clear and sharp separation of concern between the user interface (UI) logic and the business logic. The separation is clear and sharp to the point that the business logic is written with pure, vanilla, plain old dart classes without extending any external library-specific classes and without annotation or code generation.

Business logic

The business logic classes are independent of any external library. They are independent even from states_rebuilder itself.

The only constraint imposed by states_rebuilder is to ensure that methods supposed to be called from the user interface must return anything; their only role is to mutate the state (aka fields) of the class.

Another advantage of states_rebuilder is that it has practically no boilerplate. It has no boilerplate to the point that you do not have to monitor the asynchronous state yourself. You do not need to add fields to hold for example onLoadingonLoadedonError states. states_rebuilder automatically manages these asynchronous statuses and exposes the isIdle, isWaitinghasError and hasData getters and onIdleonWaitingonError and onData hooks for use in the user interface logic.

With states_rebuilder, you write business logic without bearing in mind how the user interface would interact with it.

UI logic

With states_rebuilder, you write your user interface using StatelessWidget, and when you need a business logic class, you just inject a singleton of the class using the Injector widget and get it from any child widget using the Injector.get method.

The instance obtained using Injector.get is not reactive, it is the registered singleton of the pure dart class. To make a vanilla dart class reactive, just get it using the Injector.getAsReactive method.

The model obtained is of ReactiveModel type and it is observable in the context of observer pattern. Observer widgets can subscribe to it and the observable reactive model can notify them to rebuild.

To subscribe to a ReactiveModelstates_rebuilder offers StateBuilderStateWithMixinBuilderWhenRebuilderWhenRebuilderOr and OnSetStateListener widgets.

To notify observers you call setState or setValue methods of an observable model.

With states_rebuilder, you can create as many ReactiveModels as you want from the same object, so that you can surgically control the part of the widget tree to rebuild.

`states_rebuilder` is Flutter state management combined with a dependency injection solution and an integrated router to get the best state management experience and speed up your development.

`states_rebuilder` is a feature-rich state management sulution

Examples:

Basics:

You are new to states_rebuilder this is right place to start from. The order is important:

Architecture

Note that all of the above examples are tested. With states_rebuilder, testing your business logic is the simplest part of your coding time as it is made up of simple dart classes. On the other hand, testing widgets is no less easy, because with states_rebuilder you can isolate the widget under test and mock its dependencies.

List of article about states_rebuilder

Download Flutter state management Source code on GitHub

https://github.com/GIfatahTH/states_rebuilder

Exit mobile version