Using Firebase in Flutter: Part 1 – Setup

Skip to part 2 or part 3

Firebase is a solution owned by google, which provides a ton of out of the box solutions, such as authentication, storage and analytics. In this article we are going to add user registration and login to an existing app. In order to save time we are going to skip over the app creation and assume that you already have a couple of screens set up.

Create a Firebase Project

Step one is to add Firebase to our project. Head over to the Firebase create an account if you need to and add a project.

Fill in the required information and once you are done you will be taken to a screen that looks like this:

Setup Android

Click on the Android icon and you will be directed to register your app and eventually download a google services json file. Your application ID should be the same as the one in android -> app -> build.gradle.

Once you have downloaded the google-services.json file you should copy it to your android -> app folder.

Next open up android -> build.gradle and make sure that the dependencies are included and verify that the sections in your file match the settings provided by Google:

Next open up your app level gradle file (android -> app -> build.gradle) and do the same as above:

At this point if you can run the app on an Android emulator you should be ready.

Setup iOS

Go back to the Firebase console and click “+ Add app” and click “iOS”. Head over the ios directory under your Flutter project and open the xcodeproj file contained there. You will need the bundle identifier field.

Similar to Android, download the plist file and add the plist file under the Runner directory.

That should be it. You can skip the last step because Flutter will take care of all of the Cocoapod related stuff.

The last step is adding dependencies to our pubspec.yaml file. We are going to need to add the following (versions may change):

firebase_core: "^0.5.0"
firebase_auth: "^0.18.0+1"
cloud_firestore: "^0.14.0+2"

Now click pub get and you should be good to go!