Search packages, repositories and app categories

Package detailsv0.5.2

mvvm

A Flutter MVVM. It uses property-based data binding to establish a connection between the ViewModel and the View, and drives the View changes through the ViewModel.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
63
Likes
38
Pub points
150

Install package

flutter pub add mvvm

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The mvvm package is a Flutter implementation of the Model-View-ViewModel (MVVM) architectural pattern, enabling property-based data binding between the ViewModel and View. It simplifies state management by automatically updating the UI when ViewModel properties change, reducing boilerplate code. This package supports cross-platform development across Android, iOS, Web, macOS, Windows, and Linux, making it ideal for scalable and maintainable applications. Built with clean separation of concerns, it enhances testability and developer productivity.

Use cases

  • Building scalable Flutter apps
  • Implementing reactive UIs
  • Separating business logic from presentation
  • Facilitating unit testing
  • Managing complex state flows
  • Enabling cross-platform consistency

Key features

  • Property-based data binding
  • Automatic UI updates
  • Clean separation of View and ViewModel
  • Cross-platform support
  • Minimal boilerplate
  • Testable architecture

Suitable for

  • Developers using MVVM pattern
  • Teams prioritizing maintainable code
  • Projects requiring reactive UIs
  • Large-scale Flutter applications
  • Apps needing strong testability

Considerations

  • Requires understanding of MVVM principles
  • May add complexity for simple apps
  • Limited documentation compared to mainstream packages
  • Integration with other state management solutions may need care

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

pub package

A Flutter MVVM (Model-View-ViewModel) implementation. It uses property-based data binding to establish a connection between the ViewModel and the View, and drives the View changes through the ViewModel.

一个 Flutter 的 MVVM(Model-View-ViewModel) 实现。 它使用基于属性 (property) 的数据绑定在视图模型 (ViewModel) 与视图 (View) 之间建立关联,并通过视图模型 (ViewModel) 驱动视图 (View) 变化。

import 'package:flutter/material.dart';
import 'package:mvvm/mvvm.dart';

/// ViewModel
class MyHomePageViewModel extends ViewModel {
  final timer$ = BindableProperty.$tick(
      duration: const Duration(milliseconds: 10), autostart: true, initial: 0);

  @override
  init() {
    registerProperty(#counter, BindableProperty.$value(initial: 0));
  }

  void incrementCounter() {
    updateValue<int>(#counter, (value) => value + 1);
  }
}

/// View
class MyHomePage extends View<MyHomePageViewModel> {
  final String title;
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  @override
  MyHomePageViewModel createViewModel() => MyHomePageViewModel();

  pad(int value) => '$value'.padLeft(2, '0');

  @override
  Widget build(BuildContext context, MyHomePageViewModel model) {    
    return Scaffold(
        appBar: AppBar(title: Text(title)),
        body: Center(
            child:
                Column(mainAxisAlignment: MainAxisAlignment.center, children: [
          $watch<int>(model.timer$,
              builder: (context, value, child) =>
                  Text('${pad(value ~/ 100)}.${pad(value % 100)}')),
          const Text('You have pushed the button this many times:'),
          model.$watchFor<int>(#counter,
              builder: (context, value, child) =>
                  Text('$value', style: Theme.of(context).textTheme.headline4))
        ])),
        floatingActionButton: FloatingActionButton(
            onPressed: model.incrementCounter,
            tooltip: 'Increment',
            child: const Icon(Icons.add)));
  }
}

/// run
void main() => runApp(MaterialApp(
      title: 'Flutter MVVM Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const MyHomePage(title: 'Flutter MVVM Demo Home Page'),
    ));

Examples

APIs

Documentation

BindableProperty
  • $value
  • $adaptive
  • $async
  • $custom
  • $periodic
  • $tick
  • $merge
  • $mergeMap
  • $transform
  • $filter
WidgetBuilder
  • $watch
  • $watchFor
  • $any
  • $anyFor
  • $anyMap
  • $anyMapFor
  • $cond
  • $condFor
  • $if
  • $ifFor
  • $switch
  • $switchFor
  • $select
  • $build
ViewModel
  • registerProperty
  • getProperty
  • requireProperty
  • getPropertyOf
  • requirePropertyOf
  • getProperties
  • requireProperties
  • getValue
  • requireValue
  • setValue
  • setValues
  • updateValue
  • notify
View
  • createViewModel
  • build
  • didChangeDependencies
  • activate
  • deactivate
  • didUpdateWidget
ViewBuildContext
  • setState
  • model

License

MIT

Categories

Source repository

Projects using this package

No data available yet.