Subchapter 5.4
references/flutter_setup.mdMarkdown5 KBView on GitHub
This guide covers the initial setup of Flutter and its integration with Firebase using the FlutterFire CLI.
Flutter SDK: Ensure Flutter is installed and available in the PATH.
Standard Setup (Manual):
x64) or Apple
Silicon (arm64) using uname -m.~/development/flutter).bin folder to your shell configuration (e.g.,
~/.zshrc).
echo 'export PATH="$PATH:$HOME/development/flutter/bin"' >> ~/.zshrc
source ~/.zshrcflutter doctor to ensure the SDK is correctly linked and
initialized.Firebase CLI: Ensure the Firebase CLI is available.
npx -y firebase-tools@latest --version.npx -y firebase-tools@latest login.FlutterFire CLI: Install the official FlutterFire CLI globally.
dart pub global activate flutterfire_cli.~/.pub-cache/bin is also in your PATH if flutterfire
is not found.If you don’t have a project yet, create one:
flutter create my_awesome_app
cd my_awesome_app[!IMPORTANT] For Agents: Before running the configuration command, you MUST pause and ask the developer if they prefer to:
- Create a new Firebase project, or
- Provide an existing Firebase Project ID.
flutterfire configure --project=<project_id>flutterfire configureThis tool automates:
lib/firebase_options.dart file.Add the firebase_core package and initialize it in your main.dart.
flutter pub add firebase_corelib/main.dart:import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}To add specific services (Firestore, Auth, etc.), follow the “Pub Add & Configure” pattern:
flutter pub add cloud_firestoreflutterfire configure to sync platform configurations.When creating a new project, developers often change the bundle identifier (iOS)
or applicationId (Android) after the fact. If the package names change,
flutterfire configure must be re-run to update the respective Google
service files and firebase_options.dart.
minSdkVersion (commonly
21 or 23) than the platform default. Be prepared to update
android/app/build.gradle automatically when installing certain plugins.Podfile in the /ios directory whenever
native services (like cloud_firestore) are added. If there is, run
pod install. Failing to do this will cause Xcode build errors. Note that
Flutter is moving towards Swift Package Manager (SPM), and FlutterFire
supports SPM, so a Podfile may not exist if the project only uses SPM
dependencies.When testing Firebase features locally on Chrome, requests to Google servers can
sometimes get blocked by CORS policies. Avoid relying on
--disable-web-security flags as it promotes bad security practices. Instead,
run the app on localhost with a specific port, and ensure localhost is added
to your Firebase Auth “Authorized Domains”.
flutter run -d chrome --web-hostname=localhost --web-port=5000In your main.dart, this call is mandatory before Firebase.initializeApp().
Why? Because Firebase initialization requires communication across Flutter’s
native iOS/Android method channels. ensureInitialized() guarantees the Fluter
engine is fully booted up and ready to handle these native platform calls before
runApp() executes.