Flutter, Getting Started with Firebase.

How to add firebase to flutter app ? Let’s get started.

Step 1: Set up your environment

Fluter.io provides a neat document on how to install flutter and setup your favourite IDE : Get Started

Once you have completed setup create a new Flutter project with your desired name.

Step 2: Create a Firebase project

Before adding firebase to flutter app go to Firebase console and create new Firebase project.

Tap on Add Project enter your Projects name , firebase will assign a project id based on the entered name you can also edit , Accept terms and Create project.

Your new firebase project will be created.

Step 3: Configure your app to use Firebase

To configure firebase to flutter we need some platform specific details to android and iOS apps. If you are working only on android you don’t need to add iOS specific changes.

Configure an iOS App: (Optional )

  1. In your Firebase project console overview page , Launch the iOS setup wizard.
  • Find this bundle ID by opening your app in XCode, then accessing the General tab in the top-level Runner directory. The value of the Bundle Identifier field is the iOS bundle ID (for example,com.yourcompany.yourproject). (Source)

2. Enter the Name and app store id (optional ) click next. Now download the GoogleService-info.plist

Copy the GoogleService-info.plist into iOS — Runner — Runner directory of your flutter project. In console click next and skip other steps.

Your iOS app is configured with Firebase.

Configure an Android App: (Optional )

  1. In your Firebase project console overview page , Launch the Android setup wizard.

Enter your application id into the Android package field, other fields are optional.

  • An application ID is sometimes referred to as as a package name.
  • Find this application ID in your module (app-level) Gradle file, usually android/app/build.gradle(example application ID: com.yourcompany.yourproject). (Source)

Register the app. On the next step download google-services.json and move the file into android/app folder of your flutter project.

2. Android requires another few more steps to add firebase support in your app .

In your root-level (project-level) Gradle file (android/build.gradle), add rules to include the Google Services plugin. Check that you have Google’s Maven repository, as well.

buildscript {
// ...
dependencies {
// ...
// Add the following line:
classpath 'com.google.gms:google-services:3.2.1' // Google Services plugin
}
}
allprojects {
// ...
repositories {
// Check that you have following line (if not, add it):
google() // Google's Maven repository
// ...
}
}

In your module (app-level) Gradle file (usually android/app/build.gradle), add the following line to the bottom of the file.

dependencies {
// ...
}

// ...

// Add the following line to the bottom of the file:
apply plugin: 'com.google.gms.google-services' // Gradle plugin

Run flutter packages get.

Now our app is ready to integrate flutter firebase plugins.

Open your pubspec.yaml file and add the following line under dependencies

dependencies:
flutter:
sdk: flutter
firebase_core: ^0.2.5 # add dependency for Firebase Core

Run your app and verify if app is working.

Documentation from firebase.google.com.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s