簡體   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