您好,我正在嘗試在我的顫振應用程式中實作 Firebase 身份驗證,我收到此錯誤“未定義名稱‘DefaultFirebaseOptions’。”
來自 firebase 頁面的示例源代碼:Get to know Firebase for Flutter
這是供參考的代碼:
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();
});
}
uj5u.com熱心網友回復:
這樣設定,
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"
)
);
);
所有這些資料都可以從firebase控制臺->你的專案->添加的應用程式->齒輪圖示(設定)->向下滾動找到SDK setup and configuration
。
你會在那里找到這些資訊

uj5u.com熱心網友回復:
只需使用
await Firebase.initializeApp();
googleservices.json 檔案中提供了所有其他資料
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/486762.html
