
Flutter Firebase Setup: A Step-by-Step Guide
In this post, we’ll walk through how to set up Firebase in a Flutter app from scratch. Whether you're building authentication, Firestore, or push notifications — this is your first step.
Prerequisites:
- Flutter SDK installed
- Android Studio or VS Code
- A Firebase (Google) account
Step 1: Create a Flutter Project
flutter create my_firebase_app
cd my_firebase_app
Step 2: Create a Firebase Project
- Go to Firebase Console
- Click Add project
- Give it a name (e.g.,
my_firebase_app
) - Complete the setup (disable Google Analytics if not needed)
Step 3: Add Your App to Firebase (Android)
- In Firebase Console, click Android icon
- Enter your Android package name (e.g.,
com.example.my_firebase_app
) - Download
google-services.json
- Place it in:
android/app/
Step 4: Update Android Files
1. android/build.gradle
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
}
}
2. android/app/build.gradle
apply plugin: 'com.google.gms.google-services'
Step 5: Add Firebase Packages to pubspec.yaml
dependencies:
firebase_core: ^2.30.0
Run:
flutter pub get
🔧 Step 6: Initialize Firebase in Main File
1. Update main.dart
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Firebase Setup',
home: Scaffold(
appBar: AppBar(title: Text('Firebase Connected')),
body: Center(child: Text('Hello Firebase!')),
),
);
}
}
Step 7: Run the App
flutter run
If everything is configured correctly, your app is now connected to Firebase 🎉
Bonus: Common Firebase Packages
Depending on your needs, add more packages:
# Firebase Auth
firebase_auth: ^4.17.8
# Firestore
cloud_firestore: ^4.15.4
# Push Notifications
firebase_messaging: ^15.0.1
0 Comments
Hello there! Your Flutter form submission is impeccable. The way you've seamlessly integrated form fields and handled user input showcases your mastery of Flutter's capabilities. The user experience is smooth, thanks to your thoughtful design and validation logic.
The form's visual appeal is on point, with a clean and intuitive layout that ensures users can easily interact with it. Error handling is impressive too, as it gracefully guides users through any mistakes they might make during input.
Overall, your Flutter form demonstrates your commitment to creating user-friendly and aesthetically pleasing applications. Keep up the excellent work!