パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.5.2

mvvm

Flutter MVVM。プロパティベースのデータバインディングを使用して、ViewModel と View の間で接続を確立し、ViewModel を通じて View の変更を駆動します。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
63
いいね数
38
Pub ポイント
150

パッケージをインストール

flutter pub add mvvm

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

mvvm パッケージは、Model-View-ViewModel(MVVM)アーキテクチャパターンの Flutter 実装であり、ViewModel と View の間でプロパティベースのデータバインディングを可能にします。ViewModel のプロパティが変更されたときに UI を自動的に更新することで、状態管理を簡素化し、ボイラープレートコードを削減します。このパッケージは、Android、iOS、Web、macOS、Windows、Linux でのクロスプラットフォーム開発をサポートしており、スケーラブルかつ保守可能なアプリケーションに最適です。明確な関心事の分離により、テスト性と開発生産性が向上します。

用途

  • スケーラブルなFlutterアプリの構築
  • リアクティブUIの実装
  • ビジネスロジックとプレゼンテーションの分離
  • ユニットテストの実施を支援する
  • 複雑な状態フローの管理
  • クロスプラットフォームの一貫性を有効にする

主な機能

  • プロパティベースのデータバインディング
  • 自動的な UI の更新
  • View と ViewModel の明確な分離
  • クロスプラットフォーム対応
  • 最小限のボイラープレート
  • テスト可能なアーキテクチャ

適している対象

  • MVVM パターンを使用する開発者
  • 保守性の高いコードを優先するチーム
  • リアクティブUIを必要とするプロジェクト
  • 大規模なFlutterアプリケーション
  • 高いテスト可能性を必要とするアプリ

注意事項

  • MVVM プリンシプルの理解が必要です
  • シンプルなアプリに複雑さを加える可能性がある
  • 主流パッケージと比べてドキュメントが限られている
  • 他のステート管理ソリューションとの統合には注意が必要な場合があります

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

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

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。