패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.5.2

mvvm

Flutter MVVM입니다. 속성 기반 데이터 바인딩을 사용하여 ViewModel과 뷰 사이에 연결을 설정하고, ViewModel을 통해 뷰의 변경을 유도합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
63
좋아요
38
Pub 점수
150

패키지 설치

flutter pub add mvvm

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

mvvm 패키지는 모델-뷰-뷰모델(MVVM) 아키텍처 패턴의 플러터 구현으로, 뷰모델과 뷰 간의 속성 기반 데이터 바인딩을 가능하게 합니다. 뷰모델 속성이 변경될 때 UI를 자동으로 업데이트함으로써 상태 관리를 단순화하고 반복 코드를 줄입니다. 이 패키지는 Android, iOS, 웹, macOS, Windows, Linux에서의 크로스플랫폼 개발을 지원하여 확장성 있고 유지보수 가능한 애플리케이션에 이상적입니다. 명확한 관심사 분리로 인해 테스트 가능성과 개발 생산성을 향상시킵니다.

사용 사례

  • 확장 가능한 Flutter 앱 만들기
  • 반응형 UI 구현
  • 비즈니스 로직과 표현의 분리
  • 단위 테스트 촉진
  • 복잡한 상태 흐름 관리
  • 다중 플랫폼 일관성 활성화

주요 기능

  • 속성 기반 데이터 바인딩
  • 자동 UI 업데이트
  • 뷰와 ViewModel의 명확한 분리
  • 크로스 플랫폼 지원
  • 최소한의 보일러플레이트
  • 테스트 가능한 아키텍처

적합한 대상

  • MVVM 패턴을 사용하는 개발자
  • 유지보수 가능한 코드를 우선시하는 팀
  • 반응형 UI가 필요한 프로젝트
  • 대규모 플러터 애플리케이션
  • 강력한 테스트 가능성을 필요로 하는 앱

고려 사항

  • 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

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.