Firebase helps your Flutter app store data, authenticate users, and more. Setting it up connects your app to these powerful services easily.
0
0
Firebase setup for Flutter
Introduction
You want to save user data online and sync it across devices.
You need to let users sign in with email or social accounts.
You want to send notifications to your app users.
You want to track app usage and errors automatically.
You want to add real-time chat or live updates.
Syntax
Flutter
1. Create a Firebase project at https://console.firebase.google.com 2. Add an Android and/or iOS app in the Firebase console 3. Download the config files (google-services.json for Android, GoogleService-Info.plist for iOS) 4. Place these files in your Flutter project (android/app and ios/Runner folders) 5. Add Firebase packages to pubspec.yaml 6. Initialize Firebase in your Flutter app code
You must add the config files to the correct platform folders.
Initialization code runs before your app starts to use Firebase features.
Examples
Add these lines to your pubspec.yaml to include Firebase core and authentication packages.
Flutter
dependencies: firebase_core: ^2.10.0 firebase_auth: ^4.4.0
This code initializes Firebase before running your app.
Flutter
import 'package:flutter/material.dart'; import 'package:firebase_core/firebase_core.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); runApp(MyApp()); }
Sample App
This Flutter app initializes Firebase and shows a simple message confirming setup.
Flutter
import 'package:flutter/material.dart'; import 'package:firebase_core/firebase_core.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Firebase Setup Demo', home: Scaffold( appBar: AppBar(title: const Text('Firebase Setup')), body: const Center(child: Text('Firebase is initialized!')), ), ); } }
OutputSuccess
Important Notes
Always call WidgetsFlutterBinding.ensureInitialized() before Firebase initialization.
Check your Firebase console to confirm your app is registered correctly.
Use the latest versions of Firebase packages for best compatibility.
Summary
Firebase setup connects your Flutter app to Firebase services.
Download and add platform config files to your project.
Initialize Firebase in your main function before running the app.