Skip to content
pubscout

mobx_codegen

2.8.0, released 2 months ago by vyuh.tech

Generates MobX store boilerplate from @observable, @computed and @action annotations.

Flutter FavoriteRock solid
$ flutter pub add mobx_codegen
Source repository

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.

Works with

Packages commonly used together with mobx_codegen: ones it builds on, ones built on it, and its own family.