Firebase Setup & Configuration

Firebase initialization, authentication, and core configuration

Firebase Setup

BabyShopHub relies on Firebase for real-time database, authentication, and push notifications. This document covers the initialization process and core setup.

Initialization

The app initializes Firebase before runApp() is called in main.dart. We use firebase_options.dart generated by the FlutterFire CLI.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MyApp());
}

Authentication Configuration

We use firebase_auth for all identity management.

  1. Email & Password: Native email/password auth is enabled.
  2. Google Sign-In: Configured using the google_sign_in package. Requires SHA-1 and SHA-256 fingerprints in the Firebase Console.
  3. Apple Sign-In: Configured for iOS users via sign_in_with_apple.

Firebase Options (firebase_options.dart)

This file contains the API keys, App IDs, and Sender IDs for Web, Android, and iOS. Never manually edit this file. If you add a new Firebase service, regenerate it:

flutterfire configure

Platform-Specific Setup

  • Android: The google-services.json must be placed in android/app/. The build.gradle is pre-configured with the Google Services plugin.
  • iOS: The GoogleService-Info.plist is linked via Xcode. Ensure you open ios/Runner.xcworkspace to manage it, not the .xcodeproj.
  • Web: Web keys are injected directly via firebase_options.dart.

Best Practices

  • Always catch FirebaseAuthException to display localized, user-friendly error messages.
  • Use userChanges() or authStateChanges() streams in AuthProvider rather than manually checking currentUser.

On this page