Flutter Repository Pattern Tutorial
Table of Contents
Flutter repository pattern tutorial
Following tutorial from here
There has to be a pattern for data to flow throughout the application. These pattern are useful for redundant free code.
Creating a flutter project:
$ flutter create repo_bookstore
Create models
These models are just class of for example any entity here Book is an entity and User, Posts, Story anything can be a model.
Data source
Our Flutter application will get data from somewhere right? Maybe from a server’s API or Database.
Get the source in application.
Creating an interface for repository
An abstract class is a good practice to create repository.
Creating actual repository
Create a class implementing the interface we created at previous step.
Connecting repository with frontend
Now we can create controller classes, these classes will call the functions of the repositories.
Frontend will call the controller class’s functions.
Frontend –> Controller –> Repository –> Source
State management using Providers.
Tutorial from here
Provider is package by Remi Rousselet with 3 main components:
- ChangeNotifier class in Flutter
- ChangeNotifierProvider (primarily used in our sample app)
- Consumer widgets