UniState is a package designed to provide a universal state management adapter for Flutter applications. It allows developers to seamlessly integrate various state management solutions while preserving Flutter's native code style and ensuring compatibility with ValueListenableBuilder
. This package aims to offer flexibility and ease in switching between different state management approaches.
- Preserve Code Style: Maintains consistency with Flutter's recommended code practices.
- Unified Interface: Provides a standardized way to manage state across different solutions like Bloc, Cubit, Provider, Getx, and Riverpod.
- Compatibility: Works seamlessly with Flutter's
ValueListenableBuilder
. - Ease of Migration: Simplifies transitions between different state management systems with minimal code changes.
- Decoupled Architecture: Keeps application logic independent of specific state management implementations.
Package | Pub |
---|---|
unistate_provider | |
unistate_adapter |
Add UniState to your pubspec.yaml
:
dependencies:
unistate_provider: ^latest_version
unistate_adapter: ^latest_version
Here's a simple counter app demonstrating UniState's flexibility:
// Define your state
class CounterCubit extends Cubit<int> with UnistateCubitMixin<int> {
CounterCubit() : super(0);
void increment() => emit(state 1);
void decrement() => emit(state - 1);
}
// Use in a Flutter widget
class CounterPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final stateManager = context.read<CounterCubit>();
return Scaffold(
body: Column(
children: [
Text(
'Count: ${stateManager.state}',
style: const TextStyle(fontSize: 24),
),
ElevatedButton(
onPressed: () => stateManager.increment(),
child: Text('Increment'),
),
],
),
);
}
}
Bloc | Cubit | Provider | getx |
---|---|---|---|
UniState is designed to work with multiple state management approaches, including but not limited to:
- BLoC [WIP]
- Cubit [WIP]
- Provider [WIP]
- Getx [WIP]
- Riverpod
- Agnostic Integration: Seamlessly work with different state management libraries
- Minimal Overhead: Lightweight adapter that doesn't compromise performance
- Flutter-Friendly: Maintains the natural flow and style of Flutter development
- Easy Migration: Simplify transitions between state management approaches
- Decoupled Architecture: Keep your core application logic independent of state management details
- Future-Proof Development: Easily adapt to new state management trends and technologies
- Consistent Developer Experience: Maintain a uniform approach to state management across different parts of your application
- Listener Disposal: Always dispose of listeners to avoid memory leaks.
- Version Compatibility: Ensure compatibility between UniState and state management libraries.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.