momentum 1.2.2
momentum: ^1.2.2 copied to clipboard
A super-powerful flutter state management library inspired with MVC pattern with very flexible dependency injection.
1.2.2 #
- Fixed
Routererror that happens whenpersistSaveis not specified. - Fixed
MomentumErrordoesn't overridetoString()so detailed error logs are not printed on the console.
1.2.1 #
1.2.0 #
- critical: fix
snapshot<T>()where it throws a compile-time type error in older versions of flutter. - added and refactored test methods.
- added new internal tests.
1.1.9 Critical #
1.1.8 Important #
- Changed license to BSD-3
- critical fix: reset() bug.
- fix config check bug in the "persistSave" parameter.
- (test) fixed dependOn
- added public methods for testability.
- Added internal tests.
TODO
- Add more internal tests.
- Find a workaround for issue #5
- Write docs for project-level testing.
- Refactor tests description/names.
1.1.7 Major Update #
Major changes:
- Persistent state.
- Persistent navigation/routing.
- Equatable support.
sendEvent<T>(...)and.listen<T>(...).- Official Documentation: https://xamdev.gq/momentum/#/
Minor changes:
Momentum.controller<T>is now the recommended way of getting a controller using context instead ofMomentum.of<T>.Momentum.service<T>is now the recommended way of getting a service using context instead ofMomentum.getService<T>.enableLoggingnow defaults tofalse.
✔ No breaking changes.
1.1.6 #
- New function added:
Momentum.restart(...)- Restart the app with a new momentum instance.
- To easily implement, in you
main.dartcreate a method that returnsMomentuminstance.void main() { runApp(momentum()); // call the method here instead of instantiating the Momentum. } Momentum momentum() { return Momentum( child: MyApp(), controllers: [ LoginController(), SessionController()..config(lazy: false, enableLogging: true), TimerController()..config(maxTimeTravelSteps: 5), TimeclockController(), AppController()..config(lazy: false, enableLogging: true), SettingsController()..config(lazy: false), ], services: [ Router([ Login(), Home(), Settings(), LanguageSelection(), FontScale(), ]), ], enableLogging: false, onResetAll: (context, resetAll) async { await Momentum.of<SessionController>(context).clearSession(); resetAll(context); Router.goto(context, Login); }, ); } - You can then call
Momentum.restart(...)down the tree:Momentum.restart(context, momentum()); // call momentum() which is a top level function.
1.1.5 #
-
New feature added: Services.
-
Inject anything into momentum and use them down the tree inside widgets or controllers.
-
Example code:
// main.dart Momentum( controllers: [...], services: [ ApiService(), ], child: MyApp(), ... ) // *.controller.dart void loadUser() async { model.update(loadingUser: true); var apiService = getService<ApiService>(); var user = await apiService.getUser(); // load data from server. asynchronous model.update(loadingUser: false, user: user); }
1.1.4 #
- exposed MomentumModel.controller property.
1.1.3 Breaking Changes #
bootstrap()method is now synchronous only.- added
bootstrapAsync()for separate asynchronous support. - For the execution order,
bootstrap()gets called first thenbootstrapAsync(). - added detailed logging for both
bootstrap()andbootstrapAsync()so you can see what gets executed first and the time it took.
1.1.2 #
- Fixed health check:
Fix lib/src/momentum_base.dart. (-1 points)
1.1.1 #
- New feature: Asynchronous
bootstrap()method now supports loading widget usingappLoaderparameter onMomentumroot widget. IfappLoaderis not specified a default loading widget will be shown.- You have to turn lazy loading off to enable this feature.
- Lets say one of your controllers implements
bootstrap()method asynchronously and it loads a data that takes seconds to finish:@override void bootstrap() async { // assuming we are loading some complex and big data here. var appSettings = await apiService.getAppSettings(); model.update(appSettings: appSettings); } - Now, imagine
apiService.getAppSettings()takes 3-5 seconds to load. Before yourMyApp()gets loaded, momentum will await this bootstrap method and show a loading widget until it finishes. Means, you can now do anything you want with thebootstrap()method synchronous or asynchronous. It is safe to callmodel.update(...)in this method.
1.1.0 #
- Reformatted the whole readme, reduce the number of headings.
1.0.9 #
-
New feature:
dontRebuildIfparameter forMomentumBuilder.-
This method will be called after
model.update(...)right before thebuilder. -
isTimeTravelis also provided that indicates if the model was updated by time travel methods.backward()or.forward(), returning it directly means you don't want to rebuild if an update was done with the time travel method. -
Two new properties were also added:
MomentumController.prevModelandMomentumController.nextModelwhich are properties from model history and their meaning is quite obvious. TheprevModelis the previous state andnextModelis the next state which will only have a value if you use.backward()method. If you are on the latest snapshot of the modelnextModelwill be null. -
Take a look at this example, The widget is displaying a time format
HH: mmandTimerControllerticks every500msfor accuracy. We only need to rebuild if minute property is changed, that's where thedontRebuildIfparameter comes.MomentumBuilder( controllers: [TimerController], dontRebuildIf: (controller, isTimeTravel) { var timer = controller<TimerController>(); var prevMinute = timer.prevModel.dateTime.minute; var currentMinute = timer.model.dateTime.minute; var minuteUnchanged = currentMinute == prevMinute; return minuteUnchanged; // don't rebuild the widget if "minute" is unchanged. }, builder: (context, snapshot) {...}, ) -
WARNING: This method is the same as any other
builderorbuildmethods, do not callmodel.update(...)or anything that callsbuildmethod, for example,setState(...). You'll get an infinite loop.
-
1.0.8 #
- Major update:
- updated
onResetAllto support widget operation before actually resetting all models. - improved README added lots of new content.
- updated
1.0.7 #
- fixed typos on the readme.
1.0.6 #
- updated readme added MomentumState listener section. and also fix typos.
1.0.5 #
- fix readme not properly displaying in pub.dev
1.0.4 #
- updated example project to link the correct
momentumversion frompub.dev.
1.0.3 #
- updated readme, now most parts are covered.
1.0.2 #
- added example app.
1.0.1 #
- updated error message.
1.0.0 #
- Initial version.