GithubHelp home page GithubHelp logo

babyninja1 / flutter-clean-architecture-mvvm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from harryhaivn/flutter-clean-architecture-mvvm

0.0 0.0 0.0 1.62 MB

In this article I will share a brief overview of how I implement Clean Architecture in my Flutter application.

Kotlin 1.46% Swift 1.59% Objective-C 0.15% Dart 96.81%

flutter-clean-architecture-mvvm's Introduction

Flutter Clean Architecture MVVM sample.

Sample of flutter using Clean Architecture and MVVM.

In this article, we show you how MVVM with Flutter could look like.

We’ll create a functional reactive ViewModel using Darts Stream API.

MVVM

Before we look at any code, we should get a basic understanding of MVVM (Model-View-ViewModel).

How does this look for my Android project?

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 (Pojos/Kotlin Data Classes), and Repository Interfaces

  • Application contains UI, View Objects, Android components, 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.

Repository

  • Bridge between Data layer and Domain layer
  • Connects to data sources and returns mapped data
  • Data sources include DB, Api, and RxCache (Cache of data that is constantly emitting updates to subscribers. More on this in another post).
  • Always store mapped data. E.g. Store the domain objects in the RxCache.

UseCase

  • Responsible for connecting to repository to retrieve necessary data. Can either return a Flowable that will emit each update (from RxCache), or a Single/Completable that finishes after result is retrieved.
  • This is where the business logic takes place.
  • Returns data downstream.
  • Single use.
  • Lives in Domain (No Android 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.

New Feature

  • Multi Language

flutter-clean-architecture-mvvm's People

Contributors

harryhaivn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.