Use the Firestore Emulator with Flutter


The following snippet demonstrates how to use the Firestore emulator in Flutter. Setting up the emulator allows you to create mock data on your local system during development. In some cases, this can eliminate the need for switching between dev/prod firebase projects when building your app.

🔥 Watch the advanced emulator tutorial for additional tips and tricks on this subject.

Setup the Emulator Suite

Initialize the emulator suite. Select the options for emulators & firestore when prompted, then stick with the defaults for everything else.

command line
firebase init
# Choose emulators, then firestore when prompted

firebase emulators:start

Starting the emulator should give you access to the UI on localhost:4000.

Example of Firestore emulator running locally

Example of Firestore emulator running locally

Connect Flutter to the Firestore Emulator

The Firestore emulator instance is running on localhost:8080. We can tell Flutter to use the emulator by modifying the settings after our widgets have been initialized. On an Android emulator, you must point to the IP to connect to the ‘localhost’.

file_type_flutter main.dart
import 'package:cloud_firestore/cloud_firestore.dart';
import 'dart:io' show Platform;

class _MyHomePageState extends State<MyHomePage> {

  void initState() {
    String host = Platform.isAndroid ? '' : 'localhost:8080';

      host: host,
      sslEnabled: false,
      persistenceEnabled: false,



That’s it! Your app will now use the local emulated database values instead of your real production data in the cloud. You might improve this code by using environment variables or flavors to only use the emulator when running a development build.


Ask questions via GitHub below OR chat on Slack #questions