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

GitHub リポジトリDeveloperRahnuma/Flutter-Mvvm-Clean-Setup

MVVMアプリアーキテクチャ

Model-View-ViewModel (MVVM) アーキテクチャを使用してFlutterプロジェクトをセットアップする

MVVMアプリアーキテクチャ のプロジェクト画像
スター
123
フォーク
22
最終プッシュ(UTC)
2023/01/28
プロジェクト状態
公開中

元の README

以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。

Flutter app architecture

Model–View–ViewModel (MVVM) is a very established architectural pattern when it's come to software development. Here I have tried to put MVVM in simple example which will help you to implement in any project.

Introduction

This sample demonstrates how one can

  • Setup base architecture of Flutter app using Stacked plugin
  • Use dependency injection for layers separation
  • Code generator to generate boilerplate code for DI, routes and JSON parsing
  • Make api calls using Retrofit plugin (mostly Android developers might be familier with it).

Apart from the basic architecture setup, this sample also demonstrates

  • Project folder structure
  • Navigation using ViewModel (without context)
  • Easy data sharing between the screens
  • And few more...
dependencies

Module Structure

There are 3 main modules to help separate the code. They are Data, Domain, and Application.

  • Data contains Local Storage, APIs, Data objects (Request/Response object, DB objects), and the repository implementation.

  • Domain contains UseCases, Domain Objects/Models, and Repository Interfaces

  • Application contains UI, View Objects, Widgets, etc. Can be split into separate modules itself if needed. For example, we could have a module called Device handling things like camera, location, etc.

Package structure

  • using modular architecture to architect the app per feature to be easier and more readable and isolate the feature from each other

Repository

  • Bridge between Data layer and Domain layer
  • Connects to data sources and returns mapped data
  • Data sources include DB and Api

UseCase

  • Responsible for connecting to repository to retrieve necessary data. returns a Stream that will emit each update.
  • This is where the business logic takes place.
  • Returns data downstream.
  • Single use.
  • Lives in Domain (No Platform dependencies. Very testable).

ViewModel

  • Organizes data and holds View state.
  • Talks to use cases.
  • Does not know about the View.

View

  • Updates UI
  • Knows about the ViewModel
  • Observes changes to ViewModel.

Router

  • I leave this open ended to suit each projects needs. The main point here is that it is important to consolidate navigation logic to one place. This helps with maintenance and unit testing.

Setup

One can download the code in zip format or take checkout from the git repository.

Note

You need to run build_runner command for code generation everytime when you make changes in your original file.

Todo

  • to add more unit tests to increase code coverage
  • add widget & integration testing
Rahnuma Sharib GitHub avatar
GitHub 作者

Rahnuma Sharib ↗

This is Rahnuma sharib an android ( Kotlin, java & jetpack compose ) & Flutter developer with almost 5 years of experience.

Fomo Pvt LtdNew York公式サイト ↗
言語DartSwiftKotlinObjective-C

カテゴリー

依存する Flutter コンポーネント

使用している依存関係

依存関係一覧 19 件

アプリカテゴリー

プロジェクトに合うリポジトリを選ぶには?

用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。

  1. 名前・作者・説明で検索し、技術トピックで絞り込みます。
  2. スター、フォーク、最近のプッシュを比較します。スターは関心の目安であり、品質の保証ではありません。
  3. 利用前に GitHub で README、ライセンス、Issues を確認します。

情報源と管理

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗