Flutter web firebase/firestore错误运行

Posted

技术标签:

【中文标题】Flutter web firebase/firestore错误运行【英文标题】:Flutter web firebase/firestore error running 【发布时间】:2020-09-09 17:33:16 【问题描述】:

我正在尝试使用 firebase(身份验证、firestore 数据库、存储)作为我的 Flutter 应用程序的后端。在 android/ios 上一切正常,但是当我尝试为 Flutter Web 提供服务时,它因错误而崩溃,我没有找到答案。

    at Object.firestore$ [as firestore] (http://localhost:54563/packages/firebase/src/top_level.dart.lib.js:94:55)
at new cloud_firestore_web.FirestoreWeb.new (http://localhost:54563/packages/cloud_firestore_web/src/write_batch_web.dart.lib.js:793:37)
at Function.registerWith (http://localhost:54563/packages/cloud_firestore_web/src/write_batch_web.dart.lib.js:738:71)
at Object.registerPlugins (http://localhost:54563/packages/reviewcredibility/generated_plugin_registrant.dart.lib.js:17:38)
at main$ (http://localhost:54563/web_entrypoint.dart.lib.js:15:35)
at main$.next (<anonymous>)
at runBody (http://localhost:54563/dart_sdk.js:36923:34)
at Object._async [as async] (http://localhost:54563/dart_sdk.js:36951:7)
at main$ (http://localhost:54563/web_entrypoint.dart.lib.js:14:18)
at <anonymous>:1:8
at Object.runMain (http://localhost:54563/dwds/src/injected/client.js:8343:15)
at http://localhost:54563/dwds/src/injected/client.js:22335:19
at _wrapJsFunctionForAsync_closure.$protected (http://localhost:54563/dwds/src/injected/client.js:3636:15)
at _wrapJsFunctionForAsync_closure.call$2 (http://localhost:54563/dwds/src/injected/client.js:10848:12)
at Object._asyncStartSync (http://localhost:54563/dwds/src/injected/client.js:3600:20)
at main__closure1.$call$body$main__closure (http://localhost:54563/dwds/src/injected/client.js:22347:16)
at main__closure1.call$1 (http://localhost:54563/dwds/src/injected/client.js:22279:19)
at StaticClosure._rootRunUnary [as call$2$5] (http://localhost:54563/dwds/src/injected/client.js:3958:16)
at _CustomZone.runUnary$2$2 (http://localhost:54563/dwds/src/injected/client.js:12164:39)
at _CustomZone.runUnaryGuarded$1$2 (http://localhost:54563/dwds/src/injected/client.js:12092:14)
at _ControllerSubscription._sendData$1 (http://localhost:54563/dwds/src/injected/client.js:11642:19)
at _DelayedData.perform$1 (http://localhost:54563/dwds/src/injected/client.js:11796:59)
at _PendingEvents_schedule_closure.call$0 (http://localhost:54563/dwds/src/injected/client.js:11845:14)
at Object._microtaskLoop (http://localhost:54563/dwds/src/injected/client.js:3801:21)
at StaticClosure._startMicrotaskLoop (http://localhost:54563/dwds/src/injected/client.js:3807:11)
at _AsyncRun__initializeScheduleImmediate_internalCallback.call$1 (http://localhost:54563/dwds/src/injected/client.js:10720:9)
at invokeClosure (http://localhost:54563/dwds/src/injected/client.js:1172:26)

请您提出一些修复建议?谢谢。

【问题讨论】:

【参考方案1】:

我想通了

添加网络支持时从firebase生成的文件,注意添加所有需要的文件。 Firebase 控制台仅生成 firebase-app.js 和 firebase-analytics.js ,所以如果你使用一些firebase-firestore.js、firebase-auth.js或firebase-storage.js,你必须自己把它放在那里。最好在文档中提及。

<script src="https://www.gstatic.com/firebasejs/7.14.4/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.4/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.4/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.4/firebase-storage.js"></script>

<!-- TODO: Add SDKs for Firebase products that you want to use
     https://firebase.google.com/docs/web/setup#available-libraries -->

<script>
    var firebaseConfig = 
        apiKey: "YOUR_API_KEY",
        authDomain: "YOUR_DOMAIN",
        databaseURL: "YOUR_DATABASE",
        projectId: "YOUR_PROJECT_ID",
        storageBucket: "STORAGE",
        messagingSenderId: "PUSH_ID",
        appId: "APP_ID"
    ;
    // Initialize Firebase
    firebase.initializeApp(firebaseConfig);
</script>

【讨论】:

如果您的问题仍然存在,或者您对 Firebase 产品和服务有任何其他问题或疑虑,我想将您转至 Firebase Support page。因为它们更适合为您的 Firebase 查询提供答案。

以上是关于Flutter web firebase/firestore错误运行的主要内容,如果未能解决你的问题,请参考以下文章

flutter web(3) 快速创建web工程并运行

flutter项目中添加web支持

如何将 Flutter 移动应用迁移到 Flutter Web

flutter Web端支持内嵌加载网页

Flutter web 最新进展: 发掘更多可能!

Flutter 调味移动应用和 Flutter web