Lightweight, Intuitive, Zero-overhead State Manager for Flutter
lizzwe là một giải pháp quản lý state cực kỳ nhẹ, đơn giản và hiệu quả cho Flutter.
Không phụ thuộc vào các package phức tạp, chỉ sử dụng thuần Dart và Flutter để đảm bảo tốc độ, dễ học và dễ mở rộng.
Với lizzwe, bạn có thể:
- Theo dõi và cập nhật state dễ dàng.
- Chỉ rebuild đúng phần UI cần thiết.
- Lắng nghe thay đổi state mà không cần rebuild widget.
- Quản lý nhiều state phức tạp (nested object, array, map).
- Hỗ trợ cập nhật state đồng bộ và bất đồng bộ.
Observable<T>: Quản lý và notify giá trị thay đổi.StateBuilder<T>: Rebuild UI theo Observable.StateListener<T>: Lắng nghe thay đổi mà không rebuild UI.MultipleStateListener: Lắng nghe nhiều Observable cùng lúc.StateStore: Tổ chức và quản lý nhiều Observable.
Thêm vào pubspec.yaml:
dependencies:
lizzwe:
git:
url: https://github.com/tuta-dev-iotlink/lizzwe.git
ref: mainSau đó chạy:
flutter pub getfinal counter = Observable<int>(0);
// Thêm listener
counter.addListener(() {
print('Counter changed to: ${counter.value}');
});
// Cập nhật giá trị
counter.value = 1; // Listener sẽ được gọiStateBuilder(
observable: counter,
builder: (context, value) => Text('Count: $value'),
)StateListener(
observable: counter,
listener: (previous, current) => print('Count changed from $previous to $current'),
child: YourWidget(),
)MultipleStateListener(
observables: {
'counter': counter,
'name': name,
},
listener: (values) {
print('Counter: ${values['counter']}, Name: ${values['name']}');
},
child: YourWidget(),
)final store = StateStore();
// Tạo Observable
final counter = store.create(0);
final name = store.create('test');
// Lấy Observable
final sameCounter = store.get<int>(0);lizzwe được thiết kế để tối ưu hiệu suất:**
- Không sử dụng code generation
- Không có overhead khi không có thay đổi
- Chỉ rebuild widget khi cần thiết
- Hỗ trợ buildWhen để kiểm soát rebuild
// Cũ
setState(() {
_counter++;
});
// Mới
counter.value++;// Cũ
final counter = Provider.of<int>(context);
// Mới
final counter = store.get<int>(0);// Cũ
BlocBuilder<CounterBloc, CounterState>(
builder: (context, state) => Text('${state.count}'),
)
// Mới
StateBuilder(
observable: counter,
builder: (context, value) => Text('$value'),
)Xem thêm ví dụ trong thư mục example/ của GitHub repository.
Mọi đóng góp đều được hoan nghênh! Vui lòng đọc CONTRIBUTING.md để biết thêm chi tiết.
MIT License - xem LICENSE để biết thêm chi tiết.