Using Firebase with Flutter for CRUD Operations

Kanika Ratra
Mar 1 · 3 min read

Flutter is booming in the mobile market as the next revolution. It has proven to hold the potential to win over every mobile technology and become the only choice for cross-platform app development in the future. In this article we will add Cloud Firestore to our Flutter application, perform different read, and write operation . To follow along it is crucial to understand JSON first.

What is JSON and Why do we need it ?

JSON stands for javascript object notation, it is a data-interchange format which is used for the communication purposes between two platforms . Now, the question arises why do we need JSON? It is analogous in a way how global trade runs in U.S dollars. It can become really cumbersome as each country has different currency and we need some common ground to ensure trading, thus the system agreed on U.S dollars.

In a similar way in our technological world the systems agree on a single format for data to be exchanged and use common ground i.e JSON .

Format of data to be stored in Firebase:

The model of the data looks like :

We want to have a collection named Weights having document corresponding to each user having a list of Weight model. Our weight model includes dummy data as date, weight and id.

Adding Data to Firestore:

Before beginning with storing data , we need to understand what type of data is stored in Firestore.

Firestore stores the Data in JSON format , so we have to pass JSON to it.

Since we want to have document corresponding to each user , we need to specify the document name . Variable defined as UID is defined globally in the class, which is used later to create , read , update and delete.

2. Before updating data for the first time , let’s understand how to structure the data we want to store and then how to store data would be a simple step.

Step 1 : is to structure the data -

{ListOfWeight: [{date: 19/02/2021, weight: 23.0, id: 02}, {date: 23/02/2021, weight: 24.0, id: 03}]}

Step 2: use set command- To Update data for the first time use set command -

Reading Data From Firestore:

Reading data plays a crucial role and it is really important to have the clear picture about it. The data from firestore is returned in a document snapshot , whose data property has our stored data which can be further manipulated.

Append Data to List in Firestore:

The arrays are updated using FieldValue. arrayUnion() provided by firestore.

Delete Data from List in Firestore:

The element from array are removed using FieldValue. arrayRemove() provided by firestore.

Hope this article helps you. Please don’t forget to clap, thanks in advance.

Please refer the source code below:

https://github.com/kanikaratra01081997/WeightTrackingApp

In case of any doubt , feel free to reach me .

The Startup

Get smarter at building your thing. Join The Startup’s +788K followers.

Sign up for Top 10 Stories

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +788K followers.

Kanika Ratra

Written by

Tech Explorer | Flutter Fan | Learning keeps you in the Lead

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +788K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store