套件概覽
Hydrated 是一個 Flutter 套件,提供自動持久化的 BehaviorSubject,可於應用程式重新啟動後維持狀態。專為搭配 BLoC 模式使用而設計,透過自動將狀態儲存與還原至本機儲存空間來簡化狀態管理。該套件無需手動序列化或儲存邏輯即可確保資料的韌性,非常適合用於維護使用者偏好、會話資料或快取資訊。支援所有主要平台,包含 Android、iOS、Web、macOS、Windows 與 Linux。
適用情境
- 保留使用者偏好
- 快取應用狀態
- 維護會話數據
- 重啟後恢復UI狀態
- 處理離線優先場景
主要特色
- Automatic state persistence
- Built-in serialization
- Seamless BLoC integration
- Cross-platform support
- Minimal boilerplate
適合對象
- BLoC-based state management
- Apps needing offline data retention
- Developers seeking simple persistence
- Stateful apps with minimal setup
- Projects requiring reliable data recovery
使用建議
- Requires proper serialization of state objects
- May increase initial load time due to disk I/O
- Not suitable for large datasets
- Limited to simple state types
- Depends on platform-specific storage mechanisms