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();
});
}
CodePudding user response:
Just use
await Firebase.initializeApp();
CodePudding user response:
set it such way,
await Firebase.initializeApp(
options: const FirebaseOptions(
apiKey: "//your API key",
authDomain: "//your auth domain",
projectId: "//project id",
storageBucket: "///storage",
messagingSenderId: "//message sender id",
appId: "// app id",
measurementId: "// measurementId"
)
);
);
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