【问题标题】:Flutter firebase does not initializeFlutter firebase 未初始化
【发布时间】:2022-10-16 05:27:29
【问题描述】:

收到此错误。 未处理的异常:PlatformException(null-error, Host platform returned null value for non-null return value., null, null)

我已经更新了 .yaml 中的所有 firebase 包,我仍然有这个错误


E/flutter (11230): [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 (11230): #0      FirebaseCoreHostApi.optionsFromResource (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:242:7)
E/flutter (11230): <asynchronous suspension>
E/flutter (11230): #1      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:89:25)
E/flutter (11230): <asynchronous suspension>
E/flutter (11230): #2      Firebase.initializeApp (package:firebase_core/src/firebase.dart:40:31)
E/flutter (11230): <asynchronous suspension>
E/flutter (11230): #3      main (package:mossbets/main.dart:22:3)
E/flutter (11230): <asynchronous suspension>
E/flutter (11230): 

让我还补充一点,我已经调用初始化firebase。一旦我删除了初始化,应用程序就可以正常工作但没有火力

【问题讨论】:

  • 你能分享你的android/build.gradle 文件吗?您是否添加了 google 服务依赖项。

标签: flutter firebase


【解决方案1】:

这可能是由于 Firebase CLI 与 firebase 选项的新变化所致。所以要解决这个问题,请添加:

在你的终端

$ flutterfire configure

然后在你的main

// Import the generated file
import 'firebase_options.dart';

...
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
...

您可能会被要求验证您的 firebase 帐户,以便您在终端中运行它

dart pub global activate flutterfire_cli

本文将帮助您...从第 4 步开始Article

【讨论】:

    【解决方案2】:

    将这两行添加到您的 main.dart 主函数中

    void main() async{
    
     WidgetsFlutterBinding.ensureInitialized();
      // initializing the firebase app
      await Firebase.initializeApp();
    
       
    runApp(MyApp());
    
    }
    

    【讨论】:

    • 我有两条线,但错误仍然存​​在
    • 你试过'flutter clean'和'flutter pub get upgrade'吗
    猜你喜欢
    • 2021-09-19
    • 2020-08-23
    • 1970-01-01
    • 2021-04-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    相关资源
    最近更新 更多