firebase - 添加初始化 firebase_core 后,Flutter App 卡在加载屏幕
问题描述
添加 Firebase.initializeApp() 后,我的应用卡在加载屏幕上,没有 Firebase.initializeApp(),它会显示我的登录屏幕,但如果不初始化 firebase_core,我无法在 pubspec.yaml 文件中使用任何 firebase 插件。
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()
);
}
试过这个,它加载错误屏幕并显示错误:future returned 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)
解决方案
推荐阅读
- git - Jenkins:在每次提交时运行时限制并发构建
- apache-spark - 在 Pyspark 中使用 Stringindexer 时如何将列名作为变量
- javascript - 我在哪里放置我的 html 和 js 代码来发布 microsoft word 插件?
- powerbi - 如何用列 (M) 中的最新日期替换值
- amazon-web-services - 使用 terraform 将 aws s3 用作版本控制时出错
- c - fgetc() 将回车添加到换行符
- algorithm - 在旋转数组中搜索
- javascript - 在嵌套循环中将第二个变量添加到第一个变量
- python - Python 在不同条件下最小化
- php - PHP中openssl_encrypt的输出长度