Readme
Closed this issue · 3 comments
This is a work in process flutter sample app.
It tries to show a minimalistic app state
mobx: ^2.1.3
flutter_mobx: ^2.0.6+5
class AppState {
static Observable<Company> company = Observable(Company('', []));
static Observable<User> user = Observable(User(''));
}
This is a global accessible app state. Pages, views, widgets listens to it like so:
@override
Widget build(BuildContext context) {
return Column(children: [
const Text('Company page'),
Observer(builder: (_) => Text(AppState.company.name)) // <--- rebuilds when 'company' is changed
]);
}
The Company
and User
data models shown here: https://github.com/Lelelo1/flutter_app_sample/tree/main/lib/models
AppState
AppState is a singleton than can be used with dependency injection. It can implement a interface which means a mock AppState can used. By using the dependency injection container everywhere in app, the behaviour of the app is managed in testing for instance. Mocking
AppState is an example and most probably multiple global states should be used.
It can be run now showing app state used between pages.
(The effect of Observable
and Observer
is not shown yet. To see it changes has to be made on the page being viewed (push update into app, scheduling update, ui input)
Something is not working with MobX like it is does in javascript. But there should or could be some minimal package that makes variables/properties in Store/ViewModel rebuild (specific) widgets