gpt4 book ai didi

android - 在Flutter中添加Firebase.initializeApp()的正确位置在哪里?

转载 作者:行者123 更新时间:2023-12-03 04:34:26 27 4
gpt4 key购买 nike

我对 flutter 很陌生。我一直在学习某些类(class),但是进入Firebase时,方法和属性已经发生了很大变化,并且在确定如何连接到Firebase时遇到了一些困难。
在这里,我添加了main.dart文件。

import 'package:flash_chat/screens/cart_screen.dart';
import 'package:flash_chat/screens/stationery.dart';
import 'package:flutter/material.dart';
import 'package:flash_chat/screens/welcome_screen.dart';
import 'package:flash_chat/screens/login_screen.dart';
import 'package:flash_chat/screens/registration_screen.dart';
import 'package:flash_chat/screens/chat_screen.dart';
import 'package:flash_chat/screens/buyer_screen.dart';
import 'package:firebase_core/firebase_core.dart';

void main() => runApp(FlashChat());

class FlashChat extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: WelcomeScreen.id,
routes: {
WelcomeScreen.id: (context) => WelcomeScreen(),
LoginScreen.id: (context) => LoginScreen(),
RegistrationScreen.id: (context) => RegistrationScreen(),
ChatScreen.id: (context) => ChatScreen(),
BuyerScreen.id: (context) => BuyerScreen(),
StationeryScreen.id: (context) => StationeryScreen(),
CartScreen.id: (context) => CartScreen(),
},
);
}
}
我是否需要在main.dart本身或其他地方添加它?

最佳答案

是的,firebase插件方法已更改,现在您必须先初始化firebase,然后再使用它们,我在main函数内的main.dart文件中初始化了firebase方法,如下所示。

void main() async {
WidgetsFlutterBinding.ensureInitialized();

await Firebase.initializeApp();

runApp(FlashChat());
}

关于android - 在Flutter中添加Firebase.initializeApp()的正确位置在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64377755/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com