mobx_codegen
2.8.0, released 2 months ago by vyuh.tech
Generates MobX store boilerplate from @observable, @computed and @action annotations.
What it does
Runs build_runner to create *.g.dart files that implement MobX reactivity for annotated store classes. Lets you write clean abstract stores and get generated mixins automatically.
AI-written summary of version 2.8.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want MobX state management with compile‑time generated code
- You prefer annotations over manual boilerplate
- You already use build_runner in your project
Skip it when
- You need a pure Dart/Flutter solution without code generation
- You prefer other state‑management patterns like Provider or Riverpod
Strengths
- Reduces manual MobX boilerplate
- Integrates with Dart's build system
- Keeps store definitions concise and type‑safe
Weaknesses
- Requires build_runner step and generated files
- Only works with MobX, not other state‑management libs
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 6
Add mobx_codegen to dev_dependencies, run `flutter pub run build_runner build` after defining abstract Store classes
import 'package:mobx/mobx.dart';
part 'todos.g.dart';
class Todo = TodoBase with _$Todo;
abstract class TodoBase with Store {
TodoBase(this.description);
@observable
String description = '';
@observable
bool done = false;
}Alternatives
Packages that do the same job and could replace mobx_codegen.
- json_serializable
Automatically generate code for converting Dart classes to and from JSON.
94Compare - riverpod_annotation
Annotations for riverpod_generator to enable code generation
85Compare - freezed
Code generation for immutable classes, tagged unions, and cloning without boilerplate.
96Compare - riverpod_generator
Generates Riverpod providers from annotated functions using build_runner.
85Compare
Works with
Packages commonly used together with mobx_codegen: ones it builds on, ones built on it, and its own family.
- analyzermobx_codegen depends on itPerforms static analysis of Dart code for tool integration and embedding.
- buildmobx_codegen depends on itPackage for authoring build_runner compatible code generators.
- source_genmobx_codegen depends on itSource code generation builders and utilities for the Dart build system.
- mobxmobx_codegen depends on itTransparent functional reactive state management using observables, actions, and reactions.
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.
- flutter_mobxSame familyFlutter integration for MobX, providing reactive Observer widgets.
- vyuh_node_flowSame familyFlexible node-based flow editor for Flutter to build visual diagrams and workflows.
- vyuh_diagram_flutterSame familyFlutter canvas for diagrams with pan, zoom, selection and theming