Offline Development with Flutter: A Guide to Setup a scalable Mock Environment
Have you ever been developing an application when the backend service stops working? Or perhaps you needed to work offline while traveling? These scenarios can completely halt your development process unless you have a robust simulation strategy. Introduction In this article, I’ll show you how to implement simulated remote data sources in Flutter using the get_it and injectable packages. This approach will allow you to seamlessly switch between real and simulated data sources according to your environment configuration. The Problem Managing simulated implementations manually can be complicated, especially in large projects with multiple developers. Not everyone on your team may be familiar with the manual configuration process, and maintaining these configurations individually by data source becomes increasingly difficult as your application grows. This is where dependency injection comes to the rescue, specifically using the get_it and injectable packages to automate the configuration of data sources based on different environments. Initial Setup Before diving into the implementation, make sure you have the following packages in your pubspec.yaml: dependencies: get_it: injectable: http: dev_dependencies: build_runner: injectable_generator: The Solution: Environment-Based Switching Our approach will revolve around defining different environments and injecting the appropriate implementation according to the current environment. Let’s start by setting up our environments. Defining Custom Environments First, let’s extend the base Environment class from the injectable package to define our custom environments:

Have you ever been developing an application when the backend service stops working? Or perhaps you needed to work offline while traveling? These scenarios can completely halt your development process unless you have a robust simulation strategy.
Introduction
In this article, I’ll show you how to implement simulated remote data sources in Flutter using the get_it
and injectable
packages. This approach will allow you to seamlessly switch between real and simulated data sources according to your environment configuration.
The Problem
Managing simulated implementations manually can be complicated, especially in large projects with multiple developers. Not everyone on your team may be familiar with the manual configuration process, and maintaining these configurations individually by data source becomes increasingly difficult as your application grows.
This is where dependency injection comes to the rescue, specifically using the get_it
and injectable
packages to automate the configuration of data sources based on different environments.
Initial Setup
Before diving into the implementation, make sure you have the following packages in your pubspec.yaml
:
dependencies:
get_it:
injectable:
http:
dev_dependencies:
build_runner:
injectable_generator:
The Solution: Environment-Based Switching
Our approach will revolve around defining different environments and injecting the appropriate implementation according to the current environment. Let’s start by setting up our environments.
Defining Custom Environments
First, let’s extend the base Environment
class from the injectable
package to define our custom environments: