パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.1.0

hydrated

Flutter用の自動的に永続化された BehaviorSubject で、簡単なヒドレーションを備えています。BLoCパターンと併用することを想定しています。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
385
いいね数
29
Pub ポイント
130

パッケージをインストール

flutter pub add hydrated

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Hydrated は、アプリの再起動後に状態を保持できる自動的に永続化された BehaviorSubject を提供する Flutter パッケージです。BLoC パターンとの連携を目的として設計されており、ローカルストレージへの状態の自動保存および復元により、状態管理を簡素化します。手動でのシリアライズやストレージロジックが不要でデータの耐障害性を確保し、ユーザー設定、セッションデータ、キャッシュ情報などを維持するのに最適です。Android、iOS、Web、macOS、Windows、Linux など、すべての主要プラットフォームをサポートしています。

用途

  • ユーザーの設定を保持する
  • アプリの状態をキャッシュする
  • セッションデータの維持
  • 再起動後のUI状態の復元
  • オフライン優先のシナリオの処理

主な機能

  • 自動的な状態の永続化
  • 組み込みのシリアル化
  • スムーズな BLoC 統合
  • クロスプラットフォーム対応
  • 最小限のボイラープレート

適している対象

  • BLoCベースの状態管理
  • オフラインデータ保持を必要とするアプリ
  • シンプルな永続化を求める開発者
  • 最小限のセットアップで状態を持つアプリ
  • 信頼できるデータ復旧を必要とするプロジェクト

注意事項

  • 状態オブジェクトの適切なシリアライズが必要です
  • ディスクI/Oのため、初期ロード時間が延長される可能性があります
  • 大規模なデータセットには適していません
  • 単純な状態タイプに限定
  • プラットフォーム固有のストレージメカニズムに依存する

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Hydrated

Version Build License style: solid

Hydrated provides a Subject that automatically persists to Flutter's local storage and hydrates on creation!

Easy to consume

All values are persisted with shared_preferences and restored with automatic hydration.

final count$ = HydratedSubject<int>("count", seedValue: 0);

/// count$ will automagically be hydrated with 42 next time it is created
count$.add(42);

Ready for BLoC

class HydratedBloc {
  final _count$ = HydratedSubject<int>("count", seedValue: 0);

  ValueObservable<int> get count$ => _count$.stream;
  Sink<int> get setCount => _count$.sink;

  dispose() {
    _count$.close();
  }
}

Supports simple types and serialized classes

We support all shared_preferences types.

  • int
  • double
  • bool
  • String
  • List<String>
final count$ = HydratedSubject<int>("count");

We also support serialized classes with hydrate and persist arguments.

final user$ = HydratedSubject<User>(
  "user",
  hydrate: (String s) => User.fromJson(s),
  persist: (User user) => user.toJson(),
);

Reliable

Hydrated is mock tested with all supported types and is dogfooded by its creator.

Extensible

Hydrated supports any key-value data storages -- just implement the KeyValueStore interface and you will be able to use hive, flutter_secure_storage or any other persistence solution of your choice.

class MyAwesomeKeyValueStore implements KeyValueStore {
  /// your implementation here...
}

final user = HydratedSubject<User>(
  "user",
  hydrate: (String s) => User.fromJson(s),
  persist: (User user) => user.toJson(),
  keyValueStore: MyAwesomeKeyValueStore()
);

Demo

demo of Hydrated BehaviorSubject between app restarts

Original developer

hydrated was originally developed by @lukepighetti.

カテゴリー

依存関係

依存関係一覧 2 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。