创建默认应用Flutter web时,FirebaseOptions不能为null

wvt8vs2t  于 2023-01-06  发布在  Flutter
关注(0)|答案(2)|浏览(215)

e Flutter DevTools debugger and profiler on Chrome is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:64886/Uy-qx5WCixA= Error: Assertion failed: file:///C:/Users/Mohamed%20Oueslati/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/firebase_core_web-1.7.1/lib/src/firebase_core_web.dart:207:11 options != null "FirebaseOptions cannot be null when creating the default app." at Object.throw_ [as throw] (http://localhost:64781/dart_sdk.js:5405:11) at Object.assertFailed (http://localhost:64781/dart_sdk.js:5327:15) at firebase_core_web.FirebaseCoreWeb.new.initializeApp (http://localhost:64781/packages/firebase_core_web/firebase_core_web.dart.lib.js:241:42) at initializeApp.next () at http://localhost:64781/dart_sdk.js:43063:33 at _RootZone.runUnary (http://localhost:64781/dart_sdk.js:42919:58) at _FutureListener.thenAwait.handleValue (http://localhost:64781/dart_sdk.js:37493:29) at handleValueCallback (http://localhost:64781/dart_sdk.js:38088:49) at _Future._propagateToListeners (http://localhost:64781/dart_sdk.js:38126:17) at [_completeWithValue] (http://localhost:64781/dart_sdk.js:37955:23) at http://localhost:64781/dart_sdk.js:37112:46 at _RootZone.runUnary (http://localhost:64781/dart_sdk.js:42919:58) at _FutureListener.then.handleValue (http://localhost:64781/dart_sdk.js:37493:29) at handleValueCallback (http://localhost:64781/dart_sdk.js:38088:49) at _Future._propagateToListeners (http://localhost:64781/dart_sdk.js:38126:17) at [_completeWithValue] (http://localhost:64781/dart_sdk.js:37955:23) at async._AsyncCallbackEntry.new.callback (http://localhost:64781/dart_sdk.js:37991:35) at Object._microtaskLoop (http://localhost:64781/dart_sdk.js:43223:13) at _startMicrotaskLoop (http://localhost:64781/dart_sdk.js:43229:13) at http://localhost:64781/dart_sdk.js:38359:9

ig9co6j1

ig9co6j11#

我遇到了你的问题,而试图解决这个相同的错误为自己。我不知道你是否有一个现有的Flutter应用程序或如果你正在创建一个新的,但无论哪种方式,我相信答案是相同的。
初始化Flutter web的Firebase的过程已经改变。以前你会在你的web/index.html文件中初始化Firebase,但现在你不再需要这样做。相反,当你在main.dart中调用Firebase.initializeApp时,你应该传递你的Firebase项目细节,如下所示:

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

DefaultFirebaseOptions来自firebase_options.dart文件。您应该通过将firebase_core包安装到Flutter项目中,然后从命令行运行flutterfire configure来创建此文件:

flutterfire configure

有关如何执行此操作的官方文档如下:https://firebase.google.com/docs/flutter/setup
在我的例子中,我有一个已经使用Firebase很长时间的现有Flutter项目。在版本升级后,我开始看到“Firebase Options cannot be null”错误,当运行我的项目在网络上,这是没有意义的,因为它一直在工作之前,在index.html中的配置是正确的,并没有改变。我没有意识到他们改变了这需要如何做。创建firebase_options。dart并将其添加到main中。dart完全为我解决了这个问题。

rqqzpn5f

rqqzpn5f2#

我遇到了这个问题,所以我只是使用了这个命令,它被修复了。请在执行其他操作之前尝试一次

$ flutter upgrade

相关问题