繁体   English   中英

在 WidgetsFlutterBinding.ensureInitialized() 中给出异常; 等待 Firebase.initializeApp();

[英]giving exception in WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp();

我用过

 WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

在主要功能中,它在调试时给出异常,并且模拟器在没有调试的情况下运行时显示空白屏幕

它显示以下异常 -> 发生异常。 PlatformException (PlatformException(channel-error, Unable to establish connection on channel., null, null))

我已经更新了依赖项,还添加了 firebase 核心并更新了它,请帮助我解决这个问题

我的代码显示错误的图像

酒吧的输出过时了

[*] indicates versions that are not the latest available.

Package Name              Current   Upgradable  Resolvable  Latest   

direct dependencies: all up-to-date.

dev_dependencies: all up-to-date.

transitive dependencies:
string_scanner            *1.1.0    *1.1.0      *1.1.0      1.2.0
term_glyph                *1.2.0    *1.2.0      *1.2.0      1.2.1
test_api                  *0.4.9    *0.4.9      *0.4.9      0.4.17
vector_math               *2.1.2    *2.1.2      *2.1.2      2.1.4
all dependencies are up-to-date.```

在项目 build.gradle 文件和应用程序 build.gradle 文件中检查您的 Firebase SDK 依赖项

buildscript {
  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
  }
  dependencies {
    ...
    // Add this line
    classpath 'com.google.gms:google-services:4.3.13'
  }
}

allprojects {
  ...
  repositories {
    // Check that you have the following line (if not, add it):
    google()  // Google's Maven repository
    ...
  }
}

在您的应用级 build.grandle 中:

apply plugin: 'com.android.application'
// Add this line
apply plugin: 'com.google.gms.google-services'

dependencies {
  // Import the Firebase BoM
  implementation platform('com.google.firebase:firebase-bom:30.2.0')

  // Add the dependency for the Firebase SDK for Google Analytics
  // When using the BoM, don't specify versions in Firebase dependencies
  implementation 'com.google.firebase:firebase-analytics'

  // Add the dependencies for any other desired Firebase products
  // https://firebase.google.com/docs/android/setup#available-libraries
}

您是否也再次运行flutter cleanflutter pub get

否则你能运行flutter pub outdated ans share 输出吗?

1.添加到pubspec.yaml

firebase_core :

2.添加到main.dart

import 'package:firebase_core/firebase_core.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM