flutter_mobx 1.1.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 99

flutter_mobx #

pub package Build Status Coverage Status

Flutter integration with MobX.dart.

Provides the Observer widget that listens to observables and automatically rebuilds on changes.

Example #

class CounterExample extends StatefulWidget {
  const CounterExample({Key key}) : super(key: key);

  _CounterExampleState createState() => _CounterExampleState();

class _CounterExampleState extends State<CounterExample> {
  final _counter = Counter();

  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(
          title: const Text('Counter'),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              const Text(
                'You have pushed the button this many times:',
                  builder: (_) => Text(
                        style: const TextStyle(fontSize: 20),
        floatingActionButton: FloatingActionButton(
          onPressed: _counter.increment,
          tooltip: 'Increment',
          child: const Icon(Icons.add),

Notice the use of the Observer widget that listens to _counter.value, an observable, and rebuilds on changes.

You can go here for more examples

Observer #

Observer(Widget Function(BuildContext context) builder)

The builder function will be monitored by MobX and tracks all the observables that are being used inside it. When any of the observables change, builder will be called again to rebuild the Widget. This gives you a seamless way to create a reactive Widget.

Note that the Observer will print a warning if no observables are discovered in the builder function.

1.1.0 - 1.1.0+1 #

  • Exceptions are reported more reliably with FlutterError.reportError. This also includes the stack trace, as all caught exceptions are now wrapped inside MobXCaughtException.
  • Syncing versions with pubspec.yaml

1.0.0 - 1.0.1 #

  • Ready for prime time!
  • Fixing version resolution

0.3.7 #

  • Refactoring observer.dart to separate out the StatelessObserverWidget, StatefulObserverWidget and the ObserverWidgetMixin into their own files.

0.3.6+1 - 0.3.6+2 #

  • README updates
  • Switching to Github Actions for all builds and publishing
  • Upgraded to Dart 2.7 as the min SDK

0.3.5 - 0.3.6 #

  • Updated mobx dependency version to 0.4.0 in flutter_mobx pubspec.yaml
  • Improved naming of Observer in debug-mode with the correct line in StackTrace.

Thanks to Scott Hyndman for all the contributions in this release.

0.3.4 - 0.3.4+4 #

  • Added two new Observer-widgets: StatelessObserverWidget and StatefulObserverWidget
  • Improved the reporting of Flutter errors inside Observer widgets.
  • Exposing the debugAddStackTraceInObserverName field
  • Removing the deprecated authors field from pubspec.yaml

Thanks to Scott Hyndman and Remi Rousselet for the work done in this release!

0.3.3+3 #

  • More documentation comments

0.3.2 - 0.3.3+1 #

  • Errors that occur internal to the setState() call are now reported via FlutterError.reportError so they don't go unnoticed by the user.
  • Added a version constant that matches the pubspec.yaml

0.3.0 - 0.3.1+1 #

  • Adapting to the API changes in mobx 0.3.0
  • Formatting changes
  • Using StackTrace.current as the name for an Observer, when not provided. This helps in quickly jumping to the location of the Observer-usage during debugging.
  • Docs update

0.2.3+1 #

  • Observer is relaying the exception caught during the tracking phase. This is done using the errorValue field present on the reaction instance.

0.2.2 #

  • CHANGELOG updates which got missed out in previous versions
  • The Observer does not trap exceptions occurring during the build() anymore. Previously, this used to be the case, which made it difficult to get proper stack traces.

0.2.1+1 #

  • README updates

0.2.1 #

  • Upgrading to use the 0.2.1 version of mobx, which makes it compatible with the latest beta/dev/master channels

0.2.0 #

  • Upgrading to use the 0.2.0 version of mobx

0.0.2 - 0.1.3 #

  • Warn when no observables are found in the Observer's builder function. This was originally an AssertionError, which was deemed to be too strong and caused apps to crash in debug mode.
  • Updates to tests
  • Updates to documentation

0.0.1 - First release. #

  • Observer component that re-renders when reactive variables change.


Examples #

Counter #

The default example that you get when you create a new Flutter app. Now flavored with MobX :-).

Jump to Source

Todos #

Can't miss out on the Todos! It's a classic way of showcasing a framework.

Jump to Source

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_mobx: ^1.1.0+1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_mobx/flutter_mobx.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [flutter_mobx] that is in a package requiring null.

Health suggestions

Format lib/src/stateful_observer_widget.dart.

Run flutter format to format lib/src/stateful_observer_widget.dart.

Format lib/src/stateless_observer_widget.dart.

Run flutter format to format lib/src/stateless_observer_widget.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
mobx ^1.1.0 1.2.1+1
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
mockito ^4.0.0