CT How To: Using Firebase as a Backend for Flutter Apps

By Vadim Frunza

“I need to develop a sports training app from scratch, but what should I use as the backend so I can easily connect and start working on the project?” 

Many developers ask themselves this question when they’re considering which platform to use for the backend.  

Hi, I’m Vadim, and I’m a Flutter Developer at Customertimes. I’ve been a developer for the last three years, and for the last two, I’ve worked with Flutter as a cross-platform developer. Today, I want to talk about a great solution for Flutter and any mobile or web apps: Firebase services.

This article won’t provide instructions on how to connect Firebase to a Flutter app. If you need that information, you can find it right here: https://firebase.google.com/docs/flutter/setup?platform=ios 

The objective of this article is to introduce you to Firebase services and how they can support your app’s backend. 

What is Firebase? 

Firebase was developed by Google as a platform for Backend-as-a-Service (BaaS). It offers developers the tools and services they need to construct and maintain their app’s backend. Services include hosting, user authentication, real-time database, and other features.

So why use Firebase? 

As a Flutter developer, what I find impressive about Firebase is how easily it can be used and installed.  

Firebase database (Firestore or Realtime Database) is a NoSQL database, which makes it very user friendly. Unlike SQL, where tables and rows are the norm, NoSQL databases like Firebase use collections with a list of documents, without any tables.

Firebase can be used to handle authorization, notification, storage files and other things that your apps may need, and since Google frequently updates Firebase, new features are always available. Plus the Firebase console is beautifully designed and makes collaboration between Google and Flutter very simple.

Firebase services  

Firebase has many services and solutions like Cloud Firestore, Realtime Database, Firebase Auth, Cloud Storage, Cloud Messaging, and even Firebase Machine Learning, etc. I’m going to explain the benefits of some of the major services.  

Database 

Every app needs a database. For this one, Firebase offers Cloud Firestore and Realtime Database. Both are NoSQL databases, but Cloud Firestore is an improved, redesigned version of Realtime Database. 

The main differences between Cloud Firestore and Realtime Database are their data model and scalability:  

 

Cloud Firestore is used more frequently because it works for a greater number of use cases. Here’s how a database looks on the Firebase platform:  

 

The database has quite a few interesting features, like Query Builder. Use it to search according to specific criteria:  

 

Firebase also offers a Storage feature where files can be saved and managed. I recommend managing files in Storage exactly like you manage data in a database: save files in a direct path to the related item in the database as needed. 

Cloud Functions  

If you want to execute some logic outside of the app, maybe for security or simply because you don’t want to save that logic in the app files, Firebase has a solution called Cloud Functions. Cloud Functions make it possible to execute logic in the cloud, so you can run your mobile backend code without managing servers.  

Cloud Functions read JavaScript code executed in the Node.js environment. Here’s an example. This sends a push notification when a new user signs up: 

 

This updates data in Firestore when a new file is uploaded to Firebase Storage:

Firebase Auth 

Many apps require an authorization feature, and for this, we can use Firebase Auth. Firebase Auth is a secure and easy-to-use authentication service that supports multiple platforms and can be integrated with other Firebase services for a seamless user experience. It’s very easy to connect it to an app using just a few lines of code. 

Securities

You should have an authorization in your app that allows the use of Cloud Firestore since Firebase has security rules for each database.  

This is logic that is written on the Firebase platform to keep your data secure. It can be customized in many different ways, and it should be written primarily in JavaScript syntax with a few differences. 

Here is a basic rule to access read and write operations only for authorized users:

One other security feature to consider is the AppCheck solution. 

AppCheck verifies the authenticity of requests made to Firebase APIs and services, allowing developers to define custom rules to ensure that requests are coming from trusted sources and not from bots or other automated systems that could exploit vulnerabilities in your application. It offers an extra layer of protection against malicious attacks to help keep your apps secure. 

Other useful services 

Firebase has many solutions and services that can help as you’re building your app, but if I try to list all of them here, it will be a very long article. Instead, I’m going to briefly describe a few of my favorites:  

  • Cloud Messaging – a service for sending push notifications and messages to mobile devices and web apps 
  • Machine Learning – a suite of tools for building and deploying machine learning models in the cloud 
  • Firebase Extensions – Pre-built, customizable modules that can be added to Firebase projects to automate common tasks 
  • Remote Config – a service that allows developers to remotely configure their app’s behavior without requiring a new release
  • Google Analytics – a tool for tracking user behavior and app usage, including user acquisition, engagement, and retention 
  • Performance Monitoring – a service that helps developers identify and diagnose performance issues in their app, including slow network requests and crashes 

*Note: There is a fee to use some of these services. Find out more about pricing here: https://firebase.google.com/pricing 

Conclusion 

Whether you’re building a simple mobile app or a complex web application, Firebase can provide the necessary tools and resources to help you achieve your development goals. 

It’s a powerful, versatile development platform with a user-friendly interface, flexible pricing, and simple integration with other Google services, making it an attractive option for developers of all levels of expertise. 

If you’re building an app, especially if you’re one from scratch, Firebase has the tools you need to build, test, and deploy a high-quality product.   

figure

Ready to build your own custom products?

The Product Development pros at Customertimes can help! Find out more about our product design and development services right here.

Build a Product

Vadim Frunza is Flutter developer at Customertimes with hands-on experience in developing mobile applications, using the latest innovations in Flutter and Dart.