Hello I am trying to implement firebase authentication in my flutter app I am getting this error ‘Undefined name ‘DefaultFirebaseOptions’.’
Sample source code from firebase page:Get to know Firebase for Flutter
Here is the code for reference:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';//not adding in my project?
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
import 'src/authentication.dart';
import 'src/widgets.dart';
class ApplicationState extends ChangeNotifier {
ApplicationState() {
init();
}
Future<void> init() async {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
FirebaseAuth.instance.userChanges().listen((user) {
if (user != null) {
_loginState = ApplicationLoginState.loggedIn;
} else {
_loginState = ApplicationLoginState.loggedOut;
}
notifyListeners();
});
}
2
Answers
Just use
All other data is available in googleservices.json file
set it such way,
All these data can be found from firebase console -> your project -> Added Apps -> Gear Icon (settings) -> scroll down to find
SDK setup and configuration
.
you’ll find these info there