错误:flutter/lib/ui/ui_dart_state.cc(209)] 未处理的异常:[核心/未初始化] Firebase 尚未正确初始化

发布于 2025-01-11 11:45:57 字数 2480 浏览 0 评论 0原文

我对 Dart 和一般编码都很陌生。我在 YouTube 上观看教程后编写了这段代码。在大多数情况下,我能够自己解决大部分问题,但我无法找出我最近的错误。我在 main.dart 中编写代码后立即使用 firebase 进行身份验证

Future <void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp().then((value) => Get.put(AuthController()));
runApp(const MyApp());
}

,如果我运行该应用程序,我会收到以下错误

E/flutter ( 5661): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 
[core/not-initialized] Firebase has not been correctly initialized.
E/flutter ( 5661): 
E/flutter ( 5661): Usually this means you've attempted to use a Firebase service before 
calling `Firebase.initializeApp`.
E/flutter ( 5661): 
E/flutter ( 5661): View the documentation for more information: 
https://firebase.flutter.dev/docs/overview#initialization
E/flutter ( 5661):     
E/flutter ( 5661): #0      MethodChannelFirebase.initializeApp  (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:99:9)
E/flutter ( 5661): <asynchronous suspension>
E/flutter ( 5661): #1      Firebase.initializeApp 
(package:firebase_core/src/firebase.dart:40:31)
E/flutter ( 5661): <asynchronous suspension>
E/flutter ( 5661): #2      main (package:definer_lms/main.dart:10:3)
E/flutter ( 5661): <asynchronous suspension>
E/flutter ( 5661): 

我的 android/app/build.gradle 具有以下配置:

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "getin.******.definer_lms" // edited for security purpose
    minSdkVersion 23
    targetSdkVersion 29
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    multiDexEnabled true
}
.....
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:29.1.0')
implementation 'com.android.support:multidex:1.0.3'
}

.....
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'

}

我的 android/build.gradle 具有以下配置:

dependencies {
    classpath 'com.android.tools.build:gradle:4.1.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.google.gms:google-services:4.3.10'
}

有人可以找出这里出了什么问题吗?

I am very new to Dart, and coding in general. I have produced this code after watching tutorials on YouTube. For the most part, I have been able to troubleshoot most of my problems on my own, yet I cannot figure out my most recent errors. I have using firebase for authentication as soon as I write code in main.dart

Future <void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp().then((value) => Get.put(AuthController()));
runApp(const MyApp());
}

and if i run the app, I get the following error

E/flutter ( 5661): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 
[core/not-initialized] Firebase has not been correctly initialized.
E/flutter ( 5661): 
E/flutter ( 5661): Usually this means you've attempted to use a Firebase service before 
calling `Firebase.initializeApp`.
E/flutter ( 5661): 
E/flutter ( 5661): View the documentation for more information: 
https://firebase.flutter.dev/docs/overview#initialization
E/flutter ( 5661):     
E/flutter ( 5661): #0      MethodChannelFirebase.initializeApp  (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:99:9)
E/flutter ( 5661): <asynchronous suspension>
E/flutter ( 5661): #1      Firebase.initializeApp 
(package:firebase_core/src/firebase.dart:40:31)
E/flutter ( 5661): <asynchronous suspension>
E/flutter ( 5661): #2      main (package:definer_lms/main.dart:10:3)
E/flutter ( 5661): <asynchronous suspension>
E/flutter ( 5661): 

My android/app/build.gradle has the following config:

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "getin.******.definer_lms" // edited for security purpose
    minSdkVersion 23
    targetSdkVersion 29
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    multiDexEnabled true
}
.....
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:29.1.0')
implementation 'com.android.support:multidex:1.0.3'
}

.....
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'

}

My android/build.gradle has the following config:

dependencies {
    classpath 'com.android.tools.build:gradle:4.1.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.google.gms:google-services:4.3.10'
}

can someone please find what is wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逐鹿 2025-01-18 11:45:57

你需要这样写:

  WidgetsFlutterBinding.ensureInitialized();
  
  await Firebase.initializeApp().then((value)  {
      
    Get.put(AuthController());
    
    runApp(const MyApp());
  });
 

You need to write this way :

  WidgetsFlutterBinding.ensureInitialized();
  
  await Firebase.initializeApp().then((value)  {
      
    Get.put(AuthController());
    
    runApp(const MyApp());
  });
 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文