Add Firebase in Flutter App Within 100 Seconds

Add Firebase in Flutter App Within 100 Seconds

Sure! Here’s a step-by-step guide to adding Firebase to your Flutter app:

Step 1: Create a Firebase Project

  • Go to the Firebase Console (console.firebase.google.com) and create a new project.
  • Follow the on-screen instructions to set up your project.

Step 2: Set Up Flutter Firebase Dependencies

  • Open your Flutter project in your preferred IDE or editor.
  • Open the pubspec.yaml file.
  • Add the following dependencies under the dependencies section:
  • dependencies:
    firebase_core: ^1.10.0
    firebase_auth: ^3.2.0
    cloud_firestore: ^3.1.0
    • Save the file, and run flutter pub get in your terminal to fetch the dependencies.

    Step 3: Add Firebase Configuration Files

    • Download the google-services.json file for Android or GoogleService-Info.plist for iOS from the Firebase Console.
    • For Android:
      • Move the google-services.json file to the android/app directory of your Flutter project.
    • For iOS:
      • Move the GoogleService-Info.plist file to the ios/Runner directory of your Flutter project.

    Step 4: Initialize Firebase

    • Open the main.dart file in the lib directory.
    • Import the required Firebase packages at the top of the file:
    • import ‘package:firebase_core/firebase_core.dart’;
    • Wrap the void main() function inside an async block, and call await Firebase.initializeApp() before running the app:
    • void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); runApp(MyApp()); }
    • Step 5: Test Firebase Integration

      • Now you can use Firebase services in your Flutter app.
      • For example, to authenticate users with Firebase Auth or store data in Firestore, refer to the respective Firebase Flutter package documentation and implement the desired functionality.

      That’s it! You have successfully added Firebase to your Flutter app. Remember to follow the documentation and API references of Firebase and its Flutter packages for further usage and advanced features.

      Please note that this guide assumes you have already set up your Flutter development environment and have a basic understanding of Flutter app development.


Leave a Reply

Your email address will not be published. Required fields are marked *