Skip to content
pubscout

hydrated_mobx

2.0.0, released 3 weeks ago by narek-manukyan.dev

Automatically persist and restore MobX state stores.

WASM-ready
$ flutter pub add hydrated_mobx
Source repository

What it does

Extends MobX state management library to automatically persist and restore store states across app restarts. It supports schema migration, write coalescing, multiple storage boxes, and eviction strategies.

AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You are using MobX for state management and need to persist store states.
  • You need advanced features like write coalescing, schema migration, and eviction for your persisted stores.

Skip it when

  • You use a different state management library like Riverpod or Bloc.
  • You only need simple key-value storage without state management integration.

Strengths

  • Automatic persistence and restoration of MobX stores
  • Supports schema versioning and migrations
  • Write coalescing and change detection to reduce redundant disk writes
  • Comprehensive error handling and testing utilities

Weaknesses

  • Tightly coupled to the MobX state management library
  • Requires careful storage prefix management to avoid data loss on class renaming

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
4

Initialize HydratedStorage with a directory before calling runApp.

class CounterStore = _CounterStore with _$CounterStore;

abstract class _CounterStore extends HydratedMobX with Store {
  @observable
  int count = 0;

  @override
  String get storagePrefix => 'counter';

  @override
  Map<String, dynamic>? toJson() => {'count': count};

  @override
  void fromJson(Map<String, dynamic> json) => count = json['count'] as int;
}

Alternatives

Packages that do the same job and could replace hydrated_mobx.

  • flutter_bloc

    If you want to use BLoC state management with built-in persistence via hydrated_bloc instead of MobX.

  • flutter_riverpod

    If you prefer Riverpod for state management and need a different persistence approach.

Works with

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