Flutter Firebase Setup
Google Cloud Firebase is an amazing service of Google if you want to use Cloud database , Realtime database, Google authentication, Google Analytics and many Cloud services on your flutter app. This post is going to show how to configure your flutter project to use Firebase. We will also add an Android app to Firebase so that you can add firebase to your flutter app.
Signup For Firebase
To set up your flutter project to use firebase, first of all you'll need signup Google Firebase Console and integrate it to your local Android Studio project. After completing signup process using google account Let's Create a new project on firebase and give it a name like myproject.
Now let's create our Flutter app to use firebase. For that, run this command on terminal then open it on a Code editor.
flutter create firebaseapp
Register app on Firebase
Go to android>app>src>main>Android Manifest and copy the package name because it will be needed on firebase to register our app.
Open firebase dashboard again and click Add Android app icon like the picture below.
It will ask you for package name then paste your apps package name there. I show it in the picture below.
After registering package name they will provide a configure file 'google-service.json' , just download it and paste it on your project android>app directory. You can easily drag and drop the file on this directory directly on vs code. Click register, Now your app registration complete.
Add Firebase SDK on Flutter
Let's setup Firebase SDK and add it to your local Android project. After registering your app on flutter , they will give you some dependency and plugins to install.
Copy this line and Paste it on
your project > android > build.gradle
Under the dependency section. Maybe it will be located at line number 8 on new flutter project of flutter 3.0.2. Now scroll down and copy those lines of code for firebase plugin.
Firebase Plugin
Go to your project > app > build.gradle and paste them to 'appy plugin' and 'dependency' section. They maybe located at line number 23 and the dependency section is located at the end. Here is a hierarchy of customization we made recently. Hope everything is all right! everything everywhere all at once.
Click Next and you are ready to go. Our firebase integration is success. There are some work you can for now this is optional , Create a database and real time database, because we also need them on next tutorial.
Add Firebase Dependency
Finally, we are going to initialize firebase on our app. For that, go to pubspec.yaml file and add this dependency then hit pub get button. It will add firebase core and cloud function for data base.
firebase_core: ^1.18.0
cloud_functions: ^3.2.17
Initialize Firebase on App
Now replace void main() function with the code below from main.dart file. It will initialize Firebase on your flutter app.
Your project is ready for firebase CRUD operation and Authentication. Remember , Firebase is not available for web, so please run and debug your app on real device or simulator.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
}
Your project is ready for firebase CRUD operation and Authentication. Remember , Firebase is not available for web, so please run and debug your app on real device or simulator.
Conclusion
In this tutorial , we have learned how to to integrate firebase to our flutter project step by step with pictures. Hope guys you enjoyed it. In the next tutorial we will do some firebase CRUD Operation by creating todo app using firebase. Don't forget to share with your developer friend. Thank You.