In this tutorial, we will delve into the seamless integration of a Firebase project into a Flutter app. Firebase serves as backend platform offering a wide array of services essential for modern app development. By integrating Firebase into your Flutter app, you unlock many functionalities, including real-time database management, user authentication, cloud storage, and more. Follow along as we guide you through the step-by-step process :
Step 1: Create a Firebase Project:
- Navigate to the Firebase Console.
- Now enter Project name and accept all and Continue.
- Now continue this (You can disable Google analytics ).
- Now select your loction (this will show if you select google Analytics ) .
- Congratulations! Your project created successfully , Just click on continue .
Step 2: Add Your App to Firebase:
-
- Now click on Flutter icon you seeing.
- Now Click on Next .
- install Firebase CLI .
- now copy the first command and paste it on your project terminal .
- out put is like this :
- Now run Firebase Login :
- after login run the second command :
- now use arrow keys & space to select and Selecte the platform you want to integrate with Firebase . I am Selecting Android only, after selecting hit enter.
- Now click on Flutter icon you seeing.
Step 3: Install Firebase SDK Dependencies:
- Open your Flutter project’s
pubspec.yaml
file. and Add the Firebase SDK dependencies you want to use. For example, if you’re using Firebase Authentication and Cloud Firestore, add the following dependencies:dependencies: firebase_core: ^1.10.0 firebase_auth: ^4.4.0 cloud_firestore: ^3.2.2
- Run
flutter pub get
in your terminal to install the dependencies.
Step 4: Initialize Firebase in Your Flutter App:
- Import the Firebase Core package and initialize Firebase in your app’s main entry point (usually
main.dart
):import 'package:firebase_core/firebase_core.dart'; import 'package:/firebase_options.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); runApp(MyApp()); }
- Ensure that Firebase is initialized before your app starts by using
await Firebase.initializeApp().
Congratulations! Your Firebase project has been successfully integrated with your app.