What Is Firebase?
Firebase is a Backend-as-a-Service (BaaS) app development platform that offers hosted backend services like a real-time database, cloud storage, authentication, crash reporting, machine learning, remote configuration and static file hosting.
What Will You Build?
This tutorial will walk you through the process of integrating Firebase into a Flutter app. Non-essential concepts and code blocks are glossed over, but you can copy and paste them simply thanks to the Pieces app. We also have a step-by-step guide to build a Flutter app from scratch.
Set Up a Firebase project
After you've set up and created a simple Flutter app, go to the Firebase official website here: Firebase Console
- Create a new project by clicking the Create a project button:
- Next, type in your Project Name, accept the Firebase agreement terms, and click Continue:
- Enable Google Analytics, which will provide you with detailed analytics about your project. Then, click Continue:
- Next, you can select the Google Analytics location based on your projected users. If you’re not sure, you can choose the U.S. for a location. Now, accept the Analytics terms and click Create project.
- Now, you can select the Android icon to configure Firebase with your Android application:
- Next, you’ll have to register your app by providing your app nickname and package name. You can find your app package name in Flutter here, and as shown below: project directory->android->app->src->main->AndroidManifest.xml
- Now, you can download your google-services.json file and put it inside your Flutter Project as shown below:
- To make the
google-services.jsonconfig values accessible to Firebase SDKs, you need the Google services Gradle plugin.
- Add the plugin as a
buildscriptdependency to your project-level
- Copy this line of code inside dependencies:
Root-level (project-level) Gradle file (
- Then, Select Kotlin and in your module (app-level)
build.gradlefile, add both the
google-servicesplugin and any Firebase SDKs that you want to use in your app.
- Replace following lines of code with your dependencies (last part inside
apply plugin: 'com.google.gms.google-services'
- After adding the plugin and the desired SDKs, Click Next, and Continue to Console.
Add Firebase Packages
Firebase is accessed via a variety of libraries, and there is one for each Firebase product (e.g., database, authentication, analytics or storage). Flutter provides a collection of Firebase plugins known as FlutterFire.
Available FlutterFire plugins
Steps to Add Firebase Packages into Your Project:
- Open the pubspec.yaml file from the root directory of your Flutter app.
- Add any package that you want to use, such as firebase_core:
Running the Application
- Connect your Android emulator or physical device to test the application. Next, click Build & Run.
If you want to be more productive and grab code easily from any website, try the Pieces app. It allows you to save snippets in one-click from the web or your editor, plus, it autosaves your frequently used code. Pieces also recommends snippets with Framework standards, saves snippets from screenshots and much more.