Flutter: CRUD operations using Firebase Cloud Firestore
By: Souvik Biswas
Tags: Gcp, Flutter, Firestore, Firebase, Crud

Cloud Firestore provides you an easily manageable pre-configured NoSQL database. It helps in storing & syncing data for both client and server-side development; it also supports automatic caching of data for using it even offline. Google Cloud is the driving platform behind Cloud Firestore that can be scaled easily.

In this article, you will learn to integrate Cloud Firestore with Flutter, and perform CRUD (create, read, update and delete) operations.

So, let’s get started.

Creating a Firebase project

You will need to create a new Firebase project in order to integrate it with your application.

Navigate to the Firebase console and click Add project.

Enter a project name and click Continue.

You’ll be asked whether you want to enable Google Analytics for the project. We won’t need analytics since this is just a sample project, just click Create project.

If you do want to enable Google Analytics, you’ll be prompted on the next screen to select a Google Analytics account:

Wait for the project to be created, and you’ll be navigated to the project’s Firebase dashboard.

Integrating Firebase with Android, iOS, and web

Though we’re using Flutter, which is a cross-platform framework, we still need to integrate the Firebase project separately for each platform.

Flutter 2.0 has support for Android, iOS, and web in its stable channel, so we’ll configure Firebase for all three platforms.

Android configuration

Let’s start by configuring for the Android platform.

Select the Android icon from the Firebase dashboard.

Enter the Android package name, an app nickname, and the SHA-1. Click on Register app.

Download the google-services.json file and place it in the android → app directory. Click on Next.

Just follow the instructions provided, and add the required code snippets to your project. Click on Next.

You have successfully configured Firebase for Android. On the final step, click on Continue to console to go back to the dashboard.

iOS configuration

Follow the steps below to complete the configuration on the iOS platform.

Select the iOS icon on the dashboard.

Download the GoogleService-Info.plist file. Click on Next.

Now, open the ios folder using Xcode, drag & drop the file that you downloaded into the Runner subfolder. When a dialog box appears, make sure that Runner is selected in the "Add to targets" box. Then click Finish .

folder using drag & drop the file that you downloaded into the subfolder. When a dialog box appears, make sure that is selected in the "Add to targets" box. Then click . You can skip steps 3 and 4, as they are automatically configured by the Flutter Firebase plugin that we will be adding soon. Click on Continue to console to go back to the dashboard.

Web configuration

Configure the Firebase project for the web by following the steps given below.

Select the Web icon on the dashboard.

Enter the app nickname and click on Register app.

Now, add the code snippets for integrating the Firebase SDK into the web app.

Then, click on Continue to console to navigate back to the dashboard.

Finally, you have completed the Firebase configuration for all the three platforms.

Getting started

Let’s take a look at the sample project that we will be building, and then start integrating Cloud Firestore with the Flutter app.

Project overview

We will be building a simple notes management app where you can see the list of saved notes, save new notes, and also update & delete them.