mvi 2.0.0 copy "mvi: ^2.0.0" to clipboard
mvi: ^2.0.0 copied to clipboard

A Flutter package that applies the MVI architectural pattern to help manage app state and logic in a structured and maintainable way.

Pub Version test License: MIT

MVI - Model-View-Intent for Flutter #

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.

What is MVI? #

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.

Core Components #

Base Classes #

  • 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).

ViewModels #

  • SimpleViewModel: For state management without effects.
  • ViewModel: For state management with effects support.

Mixins #

  • SimpleViewModelMixin: Mixin for connecting widgets to SimpleViewModels.
  • ViewModelMixin: Mixin for connecting widgets to ViewModels with effects support.

State Management with ValueListenable #

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.

Getting Started #

Add the package to your pubspec.yaml:

dependencies:
  mvi: ^2.0.0

Then, run flutter pub get.

Example #

Check the examples folder for complete implementations and tests:

Features #

  • 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

Contributing #

Contributions are welcome! Please feel free to submit a pull request or open an issue.

3
likes
150
points
4
downloads

Publisher

verified publisherfelipereis.me

Weekly Downloads

A Flutter package that applies the MVI architectural pattern to help manage app state and logic in a structured and maintainable way.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on mvi