hydrated_mobx 1.1.2 copy "hydrated_mobx: ^1.1.2" to clipboard
hydrated_mobx: ^1.1.2 copied to clipboard

An extension to the MobX state management library which automatically persists and restores MobX states.

HydratedMobX #

A Flutter package that automatically persists and restores MobX stores. Built to work with Flutter's state management solution MobX.

This package uses some code from hydrated_bloc by Felix Angelov, which is licensed under the MIT License. We extend our gratitude to the original authors for their work.

Features #

  • Automatically persists and restores MobX stores
  • Supports encryption for secure storage
  • Works on all platforms (iOS, Android, Web, Linux, macOS, Windows)
  • Built on top of Hive for fast and efficient storage
  • Simple and intuitive API

Getting started #

Add the package to your pubspec.yaml:

dependencies:
  hydrated_mobx: ^1.1.1

Usage #

  1. Initialize HydratedMobX in your main.dart:
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:hydrated_mobx/hydrated_mobx.dart';
import 'package:path_provider/path_provider.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final appDocumentDir = await getApplicationDocumentsDirectory();
  HydratedMobx.storage = await HydratedStorage.build(
    storageDirectory: HydratedStorageDirectory(appDocumentDir.path),
  );
  runApp(App());
}
  1. Create a hydrated store:
import 'package:mobx/mobx.dart';
import 'package:hydrated_mobx/hydrated_mobx.dart';

part 'counter_store.g.dart';

class CounterStore = _CounterStore with _$CounterStore;

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

  @action
  void increment() {
    count++;
  }

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

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

Additional information #

  • For more information about MobX, visit the MobX documentation
  • For issues and feature requests, please visit the GitHub repository
  • Contributions are welcome! Feel free to submit pull requests or open issues
6
likes
160
points
207
downloads

Publisher

verified publishernarek-manukyan.dev

Weekly Downloads

An extension to the MobX state management library which automatically persists and restores MobX states.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

hive_ce, meta, mobx, synchronized

More

Packages that depend on hydrated_mobx