Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using the flutter course "Get to know Firebase for Flutter" from https://firebase.google.com/codelabs/firebase-get-to-know-flutter#4.

I am in step_02 and I have added the following recommended code from stage 5.


import 'package:firebase_auth/firebase_auth.dart'; // new
import 'package:firebase_core/firebase_core.dart'; // new
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';           // new

import 'firebase_options.dart';                    // new
import 'src/authentication.dart';                  // new
import 'src/widgets.dart';

Later in this stage there is a Test it section. However it fails because there is no firebase_options.dart file. How do I generate this file.

Thank you.

like image 762
ubnewb Avatar asked Sep 12 '25 15:09

ubnewb


1 Answers

Previously you had to download the google-service.json and GoogleService-Info.plist files 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 project within Flutter to automate the setup which adds the necessary libraries and files to android/ and ios/ for you.

  1. Create project 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 project
  4. run flutterfire configure

This will start a command line interface for you to select the Firebase project you want to link to the Flutter project. 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());
} 
like image 189
Bugzilla Avatar answered Sep 15 '25 05:09

Bugzilla