MVC pattern for flutter. Works as state management, dependency injection and service locator.
Model View Controller
Here's a diagram describing the flow between the state (model), widget (view) and the logic (controller):
Both MomentumController and MomentumModel are abstract classes that needs to be implemented. A pair of model and controller is called a component. MomentumBuilder is simply a widget. This is used to listen to controllers for rebuilds and accessing models to display their values.
Example
If you want to see a full code example that runs. Visit the example tab for more details or you can visit the official webpage. Otherwise, if you only want to see a glimpse of how momentum works, read the Overview and FAQs below.
Advance Example:Listify (clone the repo and run the app, requires Flutter 2.0.0)
Overview
MomentumModel - the data or state. Must be Immutable.
MomentumBuilder - the view or widget to display the state.
MomentumBuilder(
controllers: [ProfileController], /// injects both `ProfileController` and `ProfileModel`.
builder: (context, snapshot) {
var profileState = snapshot<ProfileModel>(); /// grab the `ProfileModel` using snapshot.var username = profileState.username;
return// some widgets here ...
}
)
MomentumController - the logic to manipulate the model or state.