A data backend agnostic repository pattern package for Dart and Flutter

Related tags

Example Apps deposit
Overview

deposit

A data backend agnostic repository pattern package for Dart and Flutter.

Test style: very good analysis license: MIT


Overview

The goal of this package is to provide a repository pattern that is agnostic for any given data backend.

This design pattern (which comes from Domain-driven Design) helps to write data layers without having to know the data backend. This package abstracts all the aspects of the pattern into a single consistent API.

Entity

An Entity class is the base of the data model part of the repository pattern. The class defines how data from a backend should be read and it serves as a reference to that data on the backend.

Defining an Entity

class MovieEntity extends Entity {
  MovieEntity({
    this.id,
    required this.title,
  });

  factory MovieEntity.fromJSON(Map<String, dynamic> data) {
    return MovieEntity(
      id: data['id'] as int?,
      title: data['title'] as String? ?? 'No title',
    );
  }

  int? id;

  String title;

  @override
  Map<String, dynamic> toJSON() {
    return <String, dynamic>{
      'id': id,
      'title': title,
    };
  }

  @override
  String toString() => 'Movie(id: $id, title: $title)';
}

Deposit

A Deposit is a class that provides a single consistent API for the repository pattern. It uses an Entity as a relation on how to read and write data to any given data backend.

A Deposit class has a reference to table/collection on the data backend from which it can read and write data.

Creating a Deposit

You can create a Deposit in two different ways. The first one is by extending from the class itself, this allows for adding custom methods tailed to any specific usecase:

class MovieDeposit extends Deposit<MovieEntity, int> {
  MovieDeposit() : super('movies', MovieEntity.fromJSON, adapter: OptionalDepositAdapter());
}

The Deposit class can also be used directly, while this is not recommend there is also nothing against it:

final movieDeposit = Deposit<MovieEntity, int>('movies', MovieEntity.fromJSON);

DepositAdapter

The DepositAdapter is an agnostic class that defines how a Deposit instance should talk to a data backend. By default a Deposit instance will use the Deposit.defaultAdapter if no adapter was passed on initialization.

The deposit package comes with an in-memory adapter called MemoryDepositAdapter. But there is by default no adapter set, this should be done explicitly by the package user.

The following data backends are officially supported:

Setting the default adapter

By setting the Deposit.defaultAdapter any Deposit instance that did not receive an adapter on initialization will use the default adapter:

Deposit.defaultAdapter = MemoryDepositAdapter();
You might also like...

Getx Pattern example

Getx Pattern example

Oct 28, 2022

UI design for restaurant without backend

pizza_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if thi

Sep 3, 2021

A brand new Quizz App,Ui almost completed, and the firebase and storing data

A brand new Quizz App,Ui almost completed, and the firebase and storing data

a brand new Quizz App,Ui almost completed, and the firebase and storing data is the last i need to implment ,anyways thats what i acheived for now and i hope i will try to implmenet it more , Thanks

Dec 29, 2022

Flutter App with using future builder and json data

Flutter App with using future builder and json data

HOROSCOPES APP A new Flutter project with json data and Future Builder. Getting Started This project is a starting point for a Flutter application. A

Jan 26, 2022

An app that keeps track of what you're watching and allows you to watch the shows from within the app itself. It uses Kitsu API as it's data source.

Anilemon A small app to keep track of and watch your favorite anime. Features Save anime that you are interested in in your library Open the website y

Oct 12, 2021

A cross-platform BlockChain Based Application that performs Data and Sentimental Analysis using Machine Learning Algorithms.

DynaMedico Mobile App A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get yo

May 10, 2022

A Flutter News application using data from newsapi.org

A Flutter News application using data from newsapi.org

A Flutter News application using data from newsapi.org

Oct 1, 2021

Fetch weather data from cities around the globe!

Fetch weather data from cities around the globe!

Weather Today: A weather app built with mobX and the MetaWeather API This project is my first one build in flutter, and I was inspired by the Flutter

Dec 31, 2022

This is an E-commerce App that you can buy goods, it has no data base so all you see in this app are created as default

This is an E-commerce App that you can buy goods, it has no data base so all you see in this app are created as default. Once I create a server and connect with it, I will create another repository or simply update this one.

Feb 10, 2022
Owner
Blue Fire
Team working on open source packages and plugins for Flutter, including Flame, Audioplayers, Photo View, and more.
Blue Fire
Flutter Login Page Bloc Pattern App Flutter Login Page Bloc Pattern App

gdgbloc A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this

Pawan Kumar 99 Oct 20, 2022
Cryptocurrency App with MVP Design Pattern to track all the coins data in realtime for android & iOS . Written in dart using Flutter SDK.

Flutter CryptoCurrency App (MVP) Cryptocurrency App with MVP design pattern to track all the coins data in realtime for android & iOS . Written in dar

Pawan Kumar 287 Dec 30, 2022
A demo built with Flutter and Appwrite backend for Hacktoberfest 2021.

Artistry: Appwrite - Flutter Demo ?? Artistry is a demo app built with flutter and Appwrite backend for Hacktoberfest 2021, that demonstrates how to p

Divyam joshi 23 Dec 16, 2022
An e-Shop marble App, made with Flutter, and the backend with Flask (Python)

An e-Shop marble App, made with Flutter, and the backend with Flask (Python)

null 2 Nov 30, 2022
Quiz app contains flutter questions only and showing result what you got.kind of mcq pattern

quiz A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this is

jagadeesh 2 Jan 24, 2022
A simple Todo app designed to simply use GraphQL as backend and provide an easy to use UI/UX.

simple_todo_app A simple Todo app designed to simply use GraphQL as backend and provide an easy to use UI/UX. A breakdown of the project and explanati

Emir Halıcı 2 Oct 9, 2022
This repository contains all the code written throughout the 1ManStartup YouTube tutorials for building a travel budget app using Flutter

Travel Treasury Download The Live App This repository contains all the code written throughout the 1ManStartup YouTube tutorials for building a travel

Dave Faliskie 249 Dec 27, 2022
A Flutter App with Angel backend.

flutter_angel A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

Pawan Kumar 13 Jun 26, 2022
A simple shopping application made with Flutter utilizing Firebase REST APIs as a backend.

A simple shopping application made with Flutter (MVVM Architecture) utilizing Firebase (REST APIs) as a backend.

Syed Mohsin Raza 11 Aug 5, 2022
A Food DashBoard project with frontend (Flutter) & backend (Spring Boot)

food_dashboard A Food DashBoard project with frontend (Flutter) & backend (Spring Boot)

null 12 Nov 8, 2022