How to Add Firebase to Flutter App?

Firebase is a product of Google that helps developers to build, manage, and grow their apps easily. It helps developers to build their apps faster and more securely. No programming is required on the Firebase side which makes it easy to use its features more efficiently. It provides services to Android, iOS, web, and Unity. It provides cloud storage. It uses NoSQL for the database for the storage of data.

Step by Step Implementation

Step 1: First, you have to visit the Firebase console. Now let’s  move to the next step. Click on the “Add project”  as shown in the below image.

Step 2: Provide the firebase project name. Let’s give it “w3wiki”. Then click on “Continue”. Disable the “Enable Google Analytics for this project” because we don’t need this and click on “Create project”. It takes some time to wait till the project is created, After that, click on “Continue”. Now you will see the below screen, there you need to choose “Flutter” option.

DASHBOARD SCREEN -FIREBASE

Now time to add firebase to your Flutter Project.

Step 3: To add firebase to your flutter app you need to make sure that you install the “FlutterFire CLI” and “Flutter SDK” before connecting to flutter app to firebase. After you add the following packages. We can connect firebase to flutter app. For connecting firebase to flutter app we will be using the easiest and fastest way the it by using “FlutterFire CLI” through terminal.

Step 4: Open your flutter project terminal , run “firebase login” command . If you are new login give your firebase email id and password to login ,it only needed for first time login after that you can directly connect to firebase easily as shown in the given figure.

Step 5: After you logged in your firebase account, run “flutterfire configure” command in the terminal. It will give you the list of all the project available in firebase. You can find the project you created for your flutter app to connect with firebase. Use the arrow keys of the keyboard to select the project then enter to proceed further.

Step 6: After you press enter you need to choose for which platform you want to configure your flutter project . You can choose between android, ios, macos and web .If you want to create for all of them then select all of them . For moving you have to use arrow keys and to select the platforms you have to use space bar. After that just press enter and it will add all the folders related to firebase connectivity into your flutter project automatically which saves a lot of time while doing manually.

Step 7: Now your firebase is connected to flutter project. To tell your project that you want to use the features of firebase in your project you need to add some of the necessary firebase packages that is “firebase-core” and “firebase-auth”. You can install them by using command “flutter pub add package_name”. After that these packages are added in the dependencies as you can see in the below figure.

Step 8: Now impot firebase_core and firebase_auth in main.dart file and make the following changes in main() as shown in the below figure to establish a connection between flutter and firebase. Now, you can work with firebase in your project.



Contact Us