mvvm 0.3.1 copy "mvvm: ^0.3.1" to clipboard
mvvm: ^0.3.1 copied to clipboard

outdated

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.

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/widgets.dart';
import 'package:mvvm/mvvm.dart';
import 'dart:async';

// ViewModel
class Demo1ViewModel extends ViewModel {
  Demo1ViewModel() {
    registryProperty(#time, BindableProperty.$value(initial: DateTime.now()));
    start();
  }

  start() {
    Timer.periodic(const Duration(seconds: 1),
        (_) => setValue<DateTime>(#time, DateTime.now()));
  }
}

// View
class Demo1View extends View<Demo1ViewModel> {
  Demo1View() : super(Demo1ViewModel());

  format(DateTime dt) => "${dt.hour}:${dt.minute}:${dt.second}";

  @override
  Widget build(BuildContext context) {
    return Center(
        // binding
        child: $.watchFor<DateTime>(#time,
            builder: (context, time, child) =>
                Text(format(time), textDirection: TextDirection.ltr)));
  }
}

// run
void main() => runApp(Demo1View());

Watch the video

[▶️ https://www.bilibili.com/video/BV18r4y1Y7dP](https://www.bilibili.com/video/BV18r4y1Y7dP)

Example #

APIs #

ViewContext ($.*) #

Properties

Methods

override

ViewModel #

Methods

override

View #

Properties

Methods

override

Documentation

License #

MIT

36
likes
0
pub points
57%
popularity

Publisher

unverified uploader

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.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on mvvm