Pakete, Repositories und App-Kategorien suchen

GitHub-RepositoryDeveloperRahnuma/Flutter-Mvvm-Clean-Setup

MVVM-App-Architektur

Richten Sie Ihr Flutter-Projekt mit der Architektur Modell-Ansicht-ViewModel (MVVM) ein

Projektcover von MVVM-App-Architektur
Sterne
123
Forks
22
Letzter Push (UTC)
28.01.2023
Projektstatus
Aktiv

Original-README

Englischer Projektschnappschuss. Aktuelle Inhalte auf 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-Autor

Rahnuma Sharib ↗

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

Fomo Pvt LtdNew YorkOffizielle Website ↗
SprachenDartSwiftKotlinObjective-C

Kategorien

Flutter-Abhängigkeiten

Verwendete Abhängigkeiten

Abhängigkeiten 19 Einträge

App-Kategorien

Wie wähle ich ein passendes Repository?

Nach Anwendungsfall filtern, Aktivität vergleichen und vor der Nutzung das Originalprojekt prüfen.

  1. Nach Name, Autor oder Beschreibung suchen und nach Thema eingrenzen.
  2. Sterne, Forks und letzte Pushes vergleichen. Sterne zeigen Interesse, garantieren aber keine Qualität.
  3. Vor der Nutzung README, Lizenz und Issues auf GitHub prüfen.

Quellen und Pflege

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

GitHub Docs — About repositories ↗