A clean and efficient implementation of the MVI (Model-View-Intent) pattern for Flutter using ValueListenable for reactive state management.
This package provides a robust architecture to implement the MVI pattern in your Flutter projects, helping you build reactive, predictable, and testable user interfaces.
MVI is a unidirectional data flow architecture pattern that helps manage application state predictably. It consists of three main components:
- Model: Represents the state of the application. It's an immutable object that holds all the data needed for the view.
- View: The user interface (UI) that displays the state. In Flutter, this would be your widgets.
- Intent: Represents an intention to change the state. These are usually triggered by user interactions with the UI.
Additionally, this implementation supports Effects for handling one-time side effects like navigation, showing snackbars, or other UI actions that don't affect state.
BaseState: Abstract base class for all state objects. States should be immutable.BaseEvent: Abstract base class for all events (intents) that can trigger state changes.BaseEffect: Abstract base class for all effects (one-time side effects).
SimpleViewModel: For state management without effects.ViewModel: For state management with effects support.
SimpleViewModelMixin: Mixin for connecting widgets to SimpleViewModels.ViewModelMixin: Mixin for connecting widgets to ViewModels with effects support.
This MVI implementation uses Flutter's built-in ValueListenable and ValueNotifier for reactive state management. The state is observable and automatically triggers UI rebuilds when changed.
Add the package to your pubspec.yaml:
dependencies:
mvi: ^2.0.0Then, run flutter pub get.
Check the examples folder for complete implementations and tests:
examples/counter/- Simple counter app demonstrating basic MVI patternexamples/login_posts_list/- Complete app with login flow and data fetching
- ✅ Reactive State Management: Built on Flutter's ValueListenable
- ✅ Effects Support: Handle side effects like navigation and dialogs
- ✅ Performance Optimized: Selectors prevent unnecessary rebuilds
- ✅ Debug Support: Built-in logging for development
- ✅ Testable: Easy to unit test ViewModels and business logic
Contributions are welcome! Please feel free to submit a pull request or open an issue.