dart 初始化Flutter应用的Firebase时出错

8iwquhpp  于 12个月前  发布在  Flutter
关注(0)|答案(5)|浏览(137)

我试图将我的应用程序连接到Firebase,它运行良好,直到我将我的主.dart文件更改为

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

字符串
请帮助,我被困在这里,因为3天我已经尝试重新连接到firebase从头开始两次观看不同的youtube视频,但我仍然无法连接
我得到的错误:

E/flutter ( 6526): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(null-error, Host platform returned null value for non-null return value., null, null)
E/flutter ( 6526): #0      FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:248:7)
E/flutter ( 6526): <asynchronous suspension>
E/flutter ( 6526): #1      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:107:9)
E/flutter ( 6526): <asynchronous suspension>
E/flutter ( 6526): #2      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:31)
E/flutter ( 6526): <asynchronous suspension>
E/flutter ( 6526): #3      main (package:electralink/main.dart:11:3)
E/flutter ( 6526): <asynchronous suspension>
E/flutter ( 6526):

nr7wwzry

nr7wwzry1#

使用这个初始化firebase

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options:DefaultFirebaseOptions.currentPlatform);
 runApp(const MyApp());
}

字符串

p8ekf7hl

p8ekf7hl2#

我们不使用“future”main()试试这个.

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

字符串
}

dgsult0t

dgsult0t3#

在main中调用此函数,并确保您已经配置并添加了Google Play service.json和googleplay service。infoPlist

Future<void> init() async {
      WidgetsFlutterBinding.ensureInitialized(); //Add this line
    
        await Firebase.initializeApp();
      
    }

字符串
添加到Android/Build Gradle

dependencies {
    classpath 'com.google.gms:google-services:4.3.15'
    
}


添加到android/app/buildgradle在它的末尾

dependencies {
implementation platform('com.google.firebase:firebase-bom:31.0.1')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.firebase:firebase-analytics'


}

apply plugin: 'com.google.gms.google-services'


扑.干净和运行

d6kp6zgx

d6kp6zgx4#

我几天前就回答过类似的问题。给予试试吧。对我很有效。
我得到了错误,当我尝试使用firebase与Flutter

o0lyfsai

o0lyfsai5#

好吧,伙计们,我找到了解决这个问题的方法:显然,问题是与谷歌gms vesrion:这是什么Firebase网站显示添加:

```classpath 'com.google.gms:google-services:4.4.0'```

字符串
不得不将其修改为:

```classpath 'com.google.gms:google-services:4.3.15'```


它开始起作用了

相关问题