FLUTTER ECOSYSTEM

firasdarwish/hydro

Flutter 的一个简单状态管理和服务容器解决方案。

hydro 项目封面
Stars
0
Forks
0
最近推送(UTC)
2022年7月2日
项目状态
未归档
Firas M. Darwish GitHub avatar
GITHUB User

Firas M. Darwish ↗

Software Developer

语言DartHTMLSwiftKotlinObjective-C

技术话题

此仓库发布的插件

使用的依赖

依赖清单 4 项

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

展开 / 收起项目 README

hydro

A simple state management & service container solution for Flutter.

Usage
import 'package:hydro/hydro.dart';
// inherit Hydro
class SomeClass extends Hydro {
  
  String _name = "inital value";
  
  // getter
  String get name => _name;
  
  // setter
  void setName(String newName) {
    _name = newName;
    update(); // NOTE: `update()` is important to refresh the UI.
  }
  
}
// Adding to the service container
// If already been added, nothing will change.
Hydro.set(SomeClass());

// OR

// force replace an existing service, set `forceReplace: true`
Hydro.set(SomeClass(), forceReplace: true);
class _SomePageState extends State<SomePage> {
 // ...   
     
SomeClass? some_class = Hydro.get<SomeClass>(this);
// OR
SomeClass some_class = Hydro.mustGet<SomeClass>(this);

// NOTE: `get` & `mustGet` methods accept an argument of type `State`,
// it is required to refresh the UI when changes occur;
// You may as well leave it empty if UI updates are NOT needed.
// SomeClass? some_class = Hydro.get<SomeClass>();