如果我只使用 flutter web(没有 android 或 ios 应用程序),我还应该在 index.html 和 main.dart 中初始化 firebase 应用程序两次吗?
should I still initialize firebase app twice in both index.html and main.dart if i am using only flutter web(no android or ios app)?
我正在尝试构建一个纯粹作为网站的 flutter 应用程序,那么我是否应该在 index.html 和 main.dart 中两次使用 firebase 初始化应用程序?
index.html
<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "AIz...",
authDomain: "...",
databaseURL: "https://<project-name>.firebaseio.com",
projectId: "...",
storageBucket: "<project-name>.appspot.com",
messagingSenderId: "...",
appId: "...",
measurementId: "..."
};
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
Main.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
如 docs
here 中所述,您应该在两个地方都对其进行初始化。
如文档中所述,他们正在研究一种仅在一个地方对其进行初始化的方法:
We are actively investigating ways to initialize Firebase without directly using the CDN and will update the documentation once this becomes available.
我正在尝试构建一个纯粹作为网站的 flutter 应用程序,那么我是否应该在 index.html 和 main.dart 中两次使用 firebase 初始化应用程序?
index.html
<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "AIz...",
authDomain: "...",
databaseURL: "https://<project-name>.firebaseio.com",
projectId: "...",
storageBucket: "<project-name>.appspot.com",
messagingSenderId: "...",
appId: "...",
measurementId: "..."
};
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
Main.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
如 docs
here 中所述,您应该在两个地方都对其进行初始化。
如文档中所述,他们正在研究一种仅在一个地方对其进行初始化的方法:
We are actively investigating ways to initialize Firebase without directly using the CDN and will update the documentation once this becomes available.