flutter_mobx library

Provides bindings for using MobX observables with Flutter. The primary way of consuming the observables in Flutter is via the Observer widget.

The example below shows the use of an Observer that has a builder function that consumes the counter.value observable.

  Widget build(BuildContext context) => Scaffold(
       appBar: AppBar(
         backgroundColor: Colors.blue,
         title: const Text('MobX Counter'),
       ),
       body: Center(
         child: Column(
           mainAxisAlignment: MainAxisAlignment.center,
           children: <Widget>[
             const Text(
               'You have pushed the button this many times:',
             ),
             Observer(
                 builder: (_) => Text(
                       '${counter.value}',
                       style: const TextStyle(fontSize: 40),
                     )),
           ],
         ),
       ),
       floatingActionButton: FloatingActionButton(
         onPressed: counter.increment,
         tooltip: 'Increment',
         child: const Icon(Icons.add),
       ),
     );

Classes

Observer
A StatelessObserverWidget that delegate its build method to builder.
ReactionBuilder
ReactionBuilder is useful for triggering reactions via a builder function rather than creating a custom StatefulWidget for handling the same. Without a ReactionBuilder you would normally have to create a StatefulWidget where the initState() would be used to setup the reaction and then dispose it off in the dispose() method.
StatefulObserverElement
An Element that uses a StatefulObserverWidget as its configuration.
StatefulObserverWidget
A StatefulWidget that rebuilds when an Observable used inside State.build updates.
StatelessObserverElement
An Element that uses a StatelessObserverWidget as its configuration.
StatelessObserverWidget
A StatelessWidget that rebuilds when an Observable used inside build updates.

Mixins

ObserverElementMixin
A mixin that overrides build to listen to the observables used by ObserverWidgetMixin.
ObserverWidgetMixin
Observer observes the observables used in the build method and rebuilds the Widget whenever any of them change. There is no need to do any other wiring besides simply referencing the required observables.

Constants

version → const String
The version as per pubspec.yaml

Properties

debugAddStackTraceInObserverName bool
true if a stack frame indicating where an Observer was created should be included in its name. This is useful during debugging to identify the source of warnings or errors.
getter/setter pair
enableWarnWhenNoObservables bool
Whether to warn when there is no observables in the builder function
getter/setter pair

Typedefs

ReactionBuilderFunction = ReactionDisposer Function(BuildContext context)
A builder function that creates a reaction