搜尋套件、儲存庫與 APP 分類

套件詳情v2.1.0

hydrated

一個自動持久化的 BehaviorSubject,帶有 Flutter 的簡單資料還原功能。旨在與 BLoC 模式一起使用。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
385
喜歡數
29
Pub 分數
130

安裝套件

flutter pub add hydrated

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Hydrated 是一個 Flutter 套件,提供自動持久化的 BehaviorSubject,可於應用程式重新啟動後維持狀態。專為搭配 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。