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.
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.
dart pub global activate flutterfire_cli
in your Flutter projectflutterfire 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());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With