flutterfire-configure
FlutterFire Configure Skill
This skill defines how to correctly set up and configure Firebase for Flutter applications.
When to Use
Use this skill when:
- Adding Firebase to a Flutter project for the first time.
- Running
flutterfire configureafter adding a new Firebase service or platform. - Initializing Firebase in
main.dart. - Setting up separate Firebase projects for multiple app flavors.
1. Prerequisites
Install the required tools:
npm install -g firebase-tools
firebase login
dart pub global activate flutterfire_cli
Minimum platform requirements:
- Android: API level 19 (KitKat) or higher
- Apple: iOS 11 or higher
2. Setup and Configuration
# From your Flutter project directory:
flutterfire configure
# Add the core Firebase package:
flutter pub add firebase_core
- Re-run
flutterfire configureany time you add support for a new platform or start using a new Firebase service. - For Android-specific services (Crashlytics, Performance Monitoring), the FlutterFire CLI automatically adds the required Gradle plugins.
- Rebuild with
flutter runafter adding new Firebase plugins.
3. Firebase Initialization
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());
}
- Call
WidgetsFlutterBinding.ensureInitialized()before Firebase initialization. - Place Firebase initialization before any other Firebase service calls.
- Never modify
firebase_options.dartmanually — it is auto-generated. - Commit
firebase_options.dartto version control — it contains non-secret configuration identifiers. - For Firebase Emulator Suite:
await Firebase.initializeApp(demoProjectId: "demo-project-id").
4. Verification and Best Practices
After configuration, verify the setup is working:
- Run
flutter runand confirm the app launches without Firebase initialization errors. - Check the debug console for
Firebase initialized successfullyor similar confirmation. - Verify
firebase_options.dartwas generated with the correct project ID.
- Enable Firebase Analytics for optimal experience with Crashlytics, Remote Config, and other products.
- Use a consistent Firebase project across all platforms for data consistency.
- For iOS/macOS apps using certain Firebase services, add the Keychain Sharing capability in Xcode.
- Test the Firebase configuration with both debug and release builds.
- Check version compatibility between Flutter plugins and the underlying Firebase SDK.
5. Multiple App Flavors
Create separate Firebase projects per environment (development, staging, production):
flutterfire config \
--project=flutter-app-dev \
--out=lib/firebase_options_dev.dart \
--ios-bundle-id=com.example.flutterApp.dev \
--ios-out=ios/flavors/dev/GoogleService-Info.plist \
--android-package-name=com.example.flutter_app.dev \
--android-out=android/app/src/dev/google-services.json
Centralize Firebase initialization by flavor:
// firebase.dart
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app/firebase_options_prod.dart' as prod;
import 'package:flutter_app/firebase_options_stg.dart' as stg;
import 'package:flutter_app/firebase_options_dev.dart' as dev;
Future<void> initializeFirebaseApp() async {
final firebaseOptions = switch (appFlavor) {
'prod' => prod.DefaultFirebaseOptions.currentPlatform,
'stg' => stg.DefaultFirebaseOptions.currentPlatform,
'dev' => dev.DefaultFirebaseOptions.currentPlatform,
_ => throw UnsupportedError('Invalid flavor: $appFlavor'),
};
await Firebase.initializeApp(options: firebaseOptions);
}
// main.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await initializeFirebaseApp();
runApp(const MainApp());
}
- Use
appFlavoror environment variables to select the configuration at runtime. - Import each flavor's config with namespace aliases (e.g.,
as dev). - Use a helper script to automate multi-flavor configuration.
References
More from evanca/flutter-ai-rules
riverpod
Uses Riverpod for state management in Flutter/Dart. Use when setting up providers, combining requests, managing state disposal, passing arguments, performing side effects, testing providers, or applying Riverpod best practices.
28bloc
Implement Flutter state management using the bloc and flutter_bloc libraries. Use when creating a new Cubit or Bloc, modeling state with sealed classes or status enums, wiring BlocBuilder/BlocListener/BlocProvider in widgets, writing bloc unit tests, refactoring state management, or deciding between Cubit and Bloc.
21effective-dart
Apply Effective Dart guidelines to write idiomatic, high-quality Dart and Flutter code. Use when writing new Dart code, reviewing pull requests for style compliance, refactoring naming conventions, adding doc comments, structuring imports, enforcing type annotations, or running code review checks against Effective Dart standards.
20flutter-app-architecture
Implement layered Flutter app architecture with MVVM, repositories, services, and dependency injection. Use when scaffolding a new Flutter project, refactoring an existing app into layers, creating view models and repositories, configuring dependency injection, implementing unidirectional data flow, or adding a domain layer for complex business logic.
18testing
Write, review, and improve Flutter and Dart tests including unit tests, widget tests, and golden tests. Use when writing new tests, reviewing test quality, fixing flaky tests, adding test coverage, structuring test files, or choosing between unit and widget tests.
16architecture-feature-first
Structure Flutter apps using layered architecture (UI / Logic / Data) with feature-first file organization. Use when creating new features, designing the project folder structure, adding repositories, services, view models (or cubits/providers/notifiers), wiring dependency injection, or deciding which layer owns a piece of logic. State management agnostic.
16