简体   繁体   English

Flutter firebase 未初始化

[英]Flutter firebase does not initialize

am getting this error.收到此错误。 Unhandled Exception: PlatformException(null-error, Host platform returned null value for non-null return value., null, null)未处理的异常:PlatformException(空错误,主机平台为非空返回值返回 null 值。,null,空)

I have updated all firebase packages in.yaml, i still have this error我已经更新了 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): 

Let me also add i have made the call to initialize firebase.我还要补充一点,我已经调用初始化 firebase。 Once i remove the initialisation the app works fine but without firebase一旦我删除初始化应用程序工作正常但没有 firebase

add these two lines to your main.dart main function将这两行添加到您的 main.dart main function

void main() async{

 WidgetsFlutterBinding.ensureInitialized();
  // initializing the firebase app
  await Firebase.initializeApp();

   
runApp(MyApp());

}

This is probably caused by the new changes with Firebase CLI with firebase options.这可能是由带有 firebase 选项的 Firebase CLI 的新更改引起的。 So to solve this do add:所以要解决这个问题,请添加:

in your terminal在你的终端

$ flutterfire configure

then in your main然后在你的main

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

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

You probably going to be asked to authenticate your firebase account so you' ll run this in your terminal您可能会被要求验证您的 firebase 帐户,因此您将在终端中运行它

dart pub global activate flutterfire_cli

this article will help you...start from step 4 Article本文将帮助您...从第 4 步开始文章

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

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