Clean Flutter Network Architecture Using Dio (2022) | Part 0 — Introduction

Abdur Rafay Saleem
Flutter App Development
2 min readJul 4, 2022

Learn how to create the solid and flexible networking layer that can work with any REST API client and contains built in support for caching, serialization and interceptors.

Flutter Dio Networking Architecture
Flutter Dio Networking Architecture

Introduction

Networking is a vital part of apps and requires an effortless and error free setup in Flutter. It is important to setup a generic and more importantly a reusable networking layer than can be used in any Flutter project without changing code.

If you are looking for such an implementation, look no further as after following this guide you will end up with a complete solid layer to work with any API.

This is a 5 part series broken down into the following sequence:

Each of these parts can be used independently, but together they complement each other and form a solid, fully functional networking layer.

Prerequisites

Before we get started, there are a few things you need to do to prepare for your code.

  1. Install the following dependencies:
dependencies:
dio: ^4.0.6
dio_cache_interceptor: ^3.2.7
dio_cache_interceptor_hive_store: ^3.1.1
freezed_annotation: ^2.0.3
json_annotation: ^4.5.0
path_provider: ^2.0.10

2. Install the following dev_dependencies:

dev_dependencies:
build_runner: ^2.1.11
freezed: ^2.0.3+1
json_serializable: ^6.2.0

3. Next, create a file called typedefs.dart and add this line:

typedef JSON = Map<String, dynamic>;

That is all for the introduction. If you want to skip the guide and move straight to code than check out the Networking folder in UniPal GitHub repository for the full example.

Read on Part 1: Dio Service

--

--

Abdur Rafay Saleem
Flutter App Development

Flutter enthusiast by day, flutter enthusiast by night. A passionate computer science student with a focus on learning new technologies.