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
- 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
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.
In this class we define all our API Request.The methods interact with the Dio Client's methods and returns RAW data.
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. 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. 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. 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. 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.