Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Bloc | 10,235 | 210 | 164 | a day ago | 112 | August 14, 2022 | 85 | mit | Dart | |
A predictable state management library that helps implement the BLoC design pattern | ||||||||||
Getx | 8,297 | 1 | 92 | 12 days ago | 310 | August 08, 2022 | 798 | mit | Dart | |
Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get. | ||||||||||
Provider | 4,684 | 615 | 312 | 9 days ago | 59 | May 22, 2022 | 18 | mit | Dart | |
InheritedWidgets, but simple | ||||||||||
Riverpod | 4,266 | a day ago | 114 | mit | Dart | |||||
A simple way to access state while robust and testable. | ||||||||||
Mobx.dart | 2,253 | 32 | 47 | 7 days ago | 112 | September 20, 2022 | 64 | mit | Dart | |
MobX for the Dart language. Hassle-free, reactive state-management for your Dart and Flutter apps. | ||||||||||
Flutter Boilerplate Project | 1,877 | 5 months ago | 29 | mit | Dart | |||||
A boilerplate project created in flutter using MobX and Provider. | ||||||||||
Getx_pattern | 841 | 3 months ago | Makefile | |||||||
Design pattern designed to standardize your projects with GetX on Flutter. | ||||||||||
Flutter Provide | 763 | 29 | 2 | 3 years ago | 3 | February 22, 2019 | 10 | other | Dart | |
A simple framework for state management in Flutter. | ||||||||||
States_rebuilder | 478 | 11 | 2 | 3 months ago | 78 | June 13, 2022 | 9 | other | Dart | |
a simple yet powerful state management technique for Flutter | ||||||||||
Cubit | 445 | 6 | 3 years ago | 18 | July 06, 2020 | mit | Dart | |||
Cubit is a lightweight state management solution. It is a subset of the bloc package that does not rely on events and instead uses methods to emit new states. |
⚠️ Attention: This repository has been moved to https://github.com/felangel/bloc and is now read-only!
An extension to the bloc state management library which automatically persists and restores bloc states and is built on top of hydrated_cubit.
hydrated_bloc
exports a Storage
interface which means it can work with any storage provider. Out of the box, it comes with its own implementation: HydratedStorage
.
HydratedStorage
is built on top of path_provider for a platform-agnostic storage layer. The out-of-the-box storage implementation reads/writes to file using the toJson
/fromJson
methods on HydratedBloc
and should perform very well for most use-cases (performance reports coming soon). HydratedStorage
is supported for desktop (example).
HydratedStorage
void main() async {
WidgetsFlutterBinding.ensureInitialized();
HydratedBloc.storage = await HydratedStorage.build();
runApp(App());
}
HydratedBloc
and override fromJson
/toJson
enum CounterEvent { increment, decrement }
class CounterBloc extends HydratedBloc<CounterEvent, int> {
CounterBloc() : super(0);
@override
Stream<int> mapEventToState(CounterEvent event) async* {
switch (event) {
case CounterEvent.decrement:
yield state - 1;
break;
case CounterEvent.increment:
yield state + 1;
break;
}
}
@override
int fromJson(Map<String, dynamic> json) => json['value'] as int;
@override
Map<String, int> toJson(int state) => { 'value': state };
}
Now our CounterBloc
is a HydratedBloc
and will automatically persist its state. We can increment the counter value, hot restart, kill the app, etc... and our CounterBloc
will always retain its state.
By default, all data is written to temporary storage which means it can be wiped by the operating system at any point in time.
An optional storageDirectory
can be provided to override the default temporary storage directory:
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: await getApplicationDocumentsDirectory(),
);
If the default HydratedStorage
doesn't meet your needs, you can always implement a custom Storage
by simply implementing the Storage
interface and initializing HydratedBloc
with the custom Storage
.
// my_hydrated_storage.dart
class MyHydratedStorage implements Storage {
@override
dynamic read(String key) {
// TODO: implement read
}
@override
Future<void> write(String key, dynamic value) async {
// TODO: implement write
}
@override
Future<void> delete(String key) async {
// TODO: implement delete
}
@override
Future<void> clear() async {
// TODO: implement clear
}
}
// main.dart
HydratedBloc.storage = MyHydratedStorage();
Hydrated Bloc is Starware.
This means you're free to use the project, as long as you star its GitHub repository.
Your appreciation makes us grow and glow up. ⭐