mvvm_builder 1.0.8+2

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

mvvm_builder #

mvvm_builder is a Flutter plugin to help you implement MVVM design pattern with flutter. MVVM = Model - View - ViewModel

Installation #

To use this plugin, add mvvm_builder as a dependency in your pubspec.yaml file.

Why use MVVM design patterns #

Implement a good design pattern can just simplify code, make more code testable, allow better performance... The idea is to split business logic from your view. Your view has to stay dumb, and this plugin will help you to respect the pattern.

Usage #

1 - import MVVMPage Widget from package

import 'package:mvvm_builder/mvvm_builder.dart';

2 - Create your Model #

class MyViewModel extends MVVMModel {
  String title;
  List<TodoModel> todoList;

class TodoModel {
  String title, subtitle;

  TodoModel(this.title, this.subtitle);

3 - Create your Presenter #

class MyPresenter extends Presenter<MyViewModel> {

  MyPresenter(MyViewModel model, MyViewInterface view) : super(model, view);

  Future onInit() async {
    this.viewModel.title = "My todo list";
    this.viewModel.todoList = List();
    // init your view model here -- load from network etc ... 
    for(int i = 0; i < 15; i++) {
      this.viewModel.todoList.add(new TodoModel("TODO $i", "my task $i"));
    this.refreshView(); // call this at the end if onInit takes time

4 - define your view interface #

for example:

abstract class MyViewInterface {
  void showMessage(String message);

5 - Create your Page #

You page must implement your view interface. For example :

class _MyAppState extends State<MyApp> implements MyViewInterface{
  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();

  void initState() {

  Widget build(BuildContext context) {
    return MaterialApp(
      home: MVVMPage<MyPresenter, MyViewModel>(
        builder: (context, presenter, model) {
          return Scaffold(
            key: _scaffoldKey,
            appBar: AppBar(title: Text(model.title)),
            body: ListView.separated(
              itemBuilder: (context, index) => InkWell(
                onTap: () => presenter.onClickItem(index),
                child: ListTile(
                  title: Text(model.todoList[index].title),
                  subtitle: Text(model.todoList[index].subtitle),
              separatorBuilder: (context, index) => Divider(height: 1) ,
              itemCount: model.todoList.length
        presenter: MyPresenter(new MyViewModel(), this),

  void showMessage(String message) {
    _scaffoldKey.currentState.showSnackBar(new SnackBar(content: Text(message)));

Test #

This pattern is really usefull for testing as it allows you to test business logic separately from rendering. The another good thing of this pattern is the ability to test your view with many combination of viewModel settings without the need of chaining actions before having the desired view state. You can now test your view alone, presenter alone and test them together.

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

1.0.8+2 #

  • Presenter will no longer crash if call refreshView with a mockedView

1.0.8 #

  • adding presenter getter for MVVMPage in order to test
  • adding Key to MVVMPage

1.0.7+4 #

  • fix documentation

1.0.7+3 #

  • fix kotlin version to 1.3.10

1.0.7+2 #

  • fix build error on iOS : ld: symbol(s) not found for architecture arm64

1.0.7+1 #

  • fix build error on iOS : ld: symbol(s) not found for architecture arm64

1.0.7 #

  • update to swift 5

1.0.6 #

  • fix ios import swift file

1.0.5 #

  • fix pod swift version in podspec

1.0.4 #

  • fix pod swift version to => config.build_settings['SWIFT_VERSION'] = '4.2'

1.0.3 #

  • _MVVMContentState now call super.dispose first

1.0.2 #

  • kotlin_version is now '1.3.0'

1.0.1 #

  • Fix formatting i18N
  • fix pubspec descrption, removed author

1.0.0 #

  • Fix formatting
  • Removed deprecated method inheritFromWidgetOfExactType from presenter_builder

0.0.1 #

  • First version : Creates a MMVMPage with MVVM design pattern


mvvm_builder_example #

Demonstrates how to use the mvvm_builder plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  mvvm_builder: ^1.0.8+2

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:mvvm_builder/mvvm_builder.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Format lib/component_builder.dart.

Run flutter format to format lib/component_builder.dart.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Format lib/presenter_builder.dart.

Run flutter format to format lib/presenter_builder.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies