添加Firebase.initializeApp()后,我的应用卡住了加载屏幕,没有Firebase.initializeApp(),它显示了我的登录屏幕,但是如果不进行初始化,我将无法使用pubspec.yaml文件中的任何firebase插件firebase_core。
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: themeData(),
home:Login()
);
}
对此进行了尝试,它将在错误屏幕上加载以下错误:将来返回null
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FutureBuilder(
// Initialize FlutterFire
future: Firebase.initializeApp(),
builder: (context, snapshot) {
// Check for errors
if (snapshot.hasError) {
print(snapshot.error.toString);
return Error();
}
// Once complete, show your application
if (snapshot.connectionState == ConnectionState.done) {
return Login();
}
// Otherwise, show something whilst waiting for initialization to complete
return Loading();
},
);
}
}
pubpec.yaml file
google_sign_in: ^4.5.5
uuid: ^2.2.2
path_provider: ^1.6.21
firebase_storage: ^5.0.0-dev.2
firebase_messaging: ^7.0.3
cloud_firestore: ^0.14.1+3
firebase_auth: ^0.18.1+2
firebase_core: ^0.5.0+1
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[v] Flutter (Channel stable, v1.17.4, on Microsoft Windows [Version 10.0.10240], locale en-US)
[v] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
[v] Android Studio (version 3.4)
[v] VS Code (version 1.50.1)
[v] Connected device (1 available)