Missing firebase_options.dart file in course "Get to know Firebase for Flutter"

Solution 1:

Previously you had to download the google-service.json and GoogleService-Info.plist from the Firebase console and place them in the android and ios folders in your Flutter app.

Starting with Flutter 2.8, there is a new way to initialize a Firebase proyect within Flutter to bypass this step.

  1. Create proyect in Firebase console, but you don't need to download the files mentioned or change build.gradle files
  2. Install Firebase CLI here
  3. run dart pub global activate flutterfire_cli in your Flutter proyect
  4. run flutterfire configure

This will start a command line interface for you to select the Firebase proyects you want to link to the Flutter proyect. After you complete this, a firebase_options.dart file will be generated in your lib/ folder.

Finally, to initialize Firebase in your main.dart:

import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

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

PD: After updating to the new initialization method, Crashlytics and Analytics stopped working for me and I had to revert to the old initialization method. I don't think this new method is quite there yet. Guide for the old method.