Coder Social home page Coder Social logo

fakeshop's Introduction

fakeshop

Getting Started

This project is shows how to implement network calls to API resources. We use Dio package to make relevant network calls and perform crud operations

Architecture

  • Data: Contains all networking related modules
  • DI: To implement Depedency Injection
  • UI: COntains Screens and Widgets

We will use the fakestore api which provides GET, POST, PUT & DELETE resources

DioClient

To send an api request to the server, we shall need to create a Client. The Client will perform the network calls and then send us response results

By defining a client class, we set Base Url, Connection Timeout, Receive Timeout and other options. This way, we don't have to send the parameters in every request.

API Request Class

In this class we define all our API Request.The methods interact with the Dio Client's methods and returns RAW data.

Repository

Since our API Request class returns RAW data, we need to convert this data based on our model definition. So we define this behavior in a Repository Class.

Error Handling

In the Repository Class, we define a DioException Class for catching the DioError. This class will convert the Error thrown to a readable error message.

Depedency Injection

To inject the singleton classes we use the GetIt Package. Through depedency injection, we ensure that our code is loosely coupled and our classes are not highly indepedent on each other. In our scenario, the Product Repository depends on the Product API class. Additionaly, our Dio Client class depends on the Dio Class.

Building the UI

We build a minimalistic UI that has a Product Page with a list of Products. We use FutureBuilder to get the list of products. In our UI, we either show the data returned or an Error.

State Management

We use Bloc Pattern as our state management approach. Bloc allows us to define classes that can can listen for events to trigger state changes.We organiza our bloc into modules in the product module. We also add a Bloc Observer class to expose our bloc behavior as different events are received.

fakeshop's People

Contributors

dmaina5054 avatar

Watchers

James Cloos avatar  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.