mobx
2.7.0, released 2 months ago by vyuh.tech
Transparent functional reactive state management using observables, actions, and reactions.
What it does
Provides a Dart implementation of MobX for managing application state reactively. It automatically tracks dependencies when observables are read within reactions or computed properties, and triggers automatic updates when state changes. Mutations are handled via actions that batch notifications and ensure atomic updates.
AI-written summary of version 2.7.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want transparent, automatic dependency tracking without manually wiring listeners or streams
- You prefer an object-oriented store pattern with observables, actions, and computed values
- You want automatic UI rebuilds and side-effect handling with minimal boilerplate
Skip it when
- You prefer unidirectional, event-driven architectures with strictly immutable state like BLoC
- You want to avoid code generation and class mixins entirely
Strengths
- Automatic dependency tracking eliminates the need to manually subscribe or manage streams
- Computed observables automatically cache and update derived state only when dependencies change
- Actions batch changes and deliver atomic notifications
Weaknesses
- Requires companion packages (mobx_codegen and flutter_mobx) and build_runner for typical Flutter development
- Implicit tracking can make tracing unexpected updates difficult for beginners
Setup
- Kind
- Pure Dart
- Effort
- Medium
- Code generation
- No
- Direct dependencies
- 2
Typically requires mobx_codegen and build_runner in dev_dependencies to generate store mixins via annotations.
import 'package:mobx/mobx.dart';
final counter = Observable(0);
final increment = Action(() {
counter.value++;
});
final dispose = autorun((_) {
print('Count: ${counter.value}');
});
increment();
dispose();Alternatives
Packages that do the same job and could replace mobx.
- bloc
Pick bloc if you prefer explicit, stream-based event handling with immutable states over mutable observables.
92Compare - flutter_riverpod
Pick flutter_riverpod for compile-safe, declarative provider-based state management without code generation requirements.
93Compare - provider
Pick provider for simple, ChangeNotifier-based state management that aligns directly with Flutter's widget tree.
81Compare
Works with
Packages commonly used together with mobx: ones it builds on, ones built on it, and its own family.
- flutter_mobxBuilt on mobxFlutter integration for MobX, providing reactive Observer widgets.
- mobx_codegenBuilt on mobxGenerates MobX store boilerplate from @observable, @computed and @action annotations.
- vyuh_node_flowBuilt on mobxFlexible node-based flow editor for Flutter to build visual diagrams and workflows.
- vyuh_diagram_flutterBuilt on mobxFlutter canvas for diagrams with pan, zoom, selection and theming
- hydrated_mobxBuilt on mobxAutomatically persist and restore MobX state stores.