flutterfire-configure

$npx mdskill add evanca/flutter-ai-rules/flutterfire-configure

Configure Firebase for Flutter apps using the FlutterFire CLI.

  • Automates Firebase initialization and project setup for Flutter applications.
  • Integrates with firebase-tools and flutterfire_cli for seamless configuration.
  • Executes platform-specific setup based on detected Flutter project structure.
  • Outputs configuration files and CLI commands directly to the terminal.

SKILL.md

.github/skills/flutterfire-configureView on GitHub ↗
---
name: flutterfire-configure
description: Sets up Firebase for Flutter apps using FlutterFire CLI. Use when initializing a Firebase project, running flutterfire configure, initializing Firebase in main.dart, or configuring multiple app flavors.
---

# 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 configure` after 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:

```bash
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

```bash
# From your Flutter project directory:
flutterfire configure

# Add the core Firebase package:
flutter pub add firebase_core
```

- Re-run `flutterfire configure` any 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 run` after adding new Firebase plugins.

---

## 3. Firebase Initialization

```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());
}
```

- Call `WidgetsFlutterBinding.ensureInitialized()` **before** Firebase initialization.
- Place Firebase initialization **before** any other Firebase service calls.
- **Never modify** `firebase_options.dart` manually — it is auto-generated.
- **Commit** `firebase_options.dart` to version control — it contains non-secret configuration identifiers.
- For Firebase Emulator Suite: `await Firebase.initializeApp(demoProjectId: "demo-project-id")`.

---

## 4. Best Practices

- 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 your 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):

```bash
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:**

```dart
// 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);
}
```

```dart
// main.dart
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await initializeFirebaseApp();
  runApp(const MainApp());
}
```

- Use `appFlavor` or 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

- [Add Firebase to your Flutter app](https://firebase.google.com/docs/flutter/setup)
- [FlutterFire CLI](https://firebase.flutter.dev/docs/cli)

More from evanca/flutter-ai-rules

SkillDescription
architecture-feature-firstStructures Flutter apps using layered architecture (UI / Logic / Data) with feature-first file organization. Use when creating new features, designing the project structure, adding repositories/services/view models (or cubits/providers/notifiers), or wiring dependency injection. State management agnostic.
blocImplements Flutter state management using the bloc library (Bloc and Cubit). Use when creating new features, screens, or state management logic with bloc/cubit, modeling state, wiring Flutter widgets to blocs, or writing bloc/cubit unit tests.
dart-3-updatesApplies Dart 3 language features in Flutter/Dart code. Use when writing if-else or switch statements, creating new classes, or deciding between a data class and a record.
effective-dartApplies Effective Dart guidelines in Flutter/Dart code. Use when writing or reviewing Dart code for naming conventions, types, style, imports, file structure, usage patterns, documentation, testing, widgets, state management, or performance.
firebase-aiIntegrates Firebase AI Logic into Flutter apps. Use when setting up the firebase_ai plugin, calling Gemini models, handling AI service errors, or applying security and privacy considerations for AI features.
firebase-analyticsIntegrates Firebase Analytics into Flutter apps. Use when setting up analytics, logging events, setting user properties, or configuring event parameters.
firebase-app-checkIntegrates Firebase App Check into Flutter apps. Use when setting up App Check, selecting providers per platform, using debug providers during development, enabling enforcement, or applying App Check security best practices.
firebase-authIntegrates Firebase Authentication into Flutter apps. Use when setting up auth, managing auth state, implementing email/password or social sign-in, handling auth errors, managing users, or applying security best practices.
firebase-cloud-firestoreIntegrates Cloud Firestore into Flutter apps. Use when setting up Firestore, designing document/collection structure, reading and writing data, working with real-time listeners, designing for scale, or applying security rules.
firebase-cloud-functionsCalls Firebase Cloud Functions from Flutter apps. Use when setting up callable functions, passing data to functions, handling errors from function calls, optimizing performance, or testing with the Firebase Emulator Suite.