【问题标题】:Firebase Firestore Bundle not working Flutter WebFirebase Firestore Bundle 无法正常工作 Flutter Web
【发布时间】:2021-12-12 02:32:11
【问题描述】:

莫恩,

我第一次在 Flutter Web 上实现 Firestore 包。 当我在 Chrome 模拟器中本地运行 Flutter 时,一切正常。 当我像 Firebase Hosting 一样将我的项目上传到网络时,它失败了。 我在 Firebase 存储上创建并托管了一个包。

var buffer = await FirebaseStorage.instance.ref('exports/companyBundle.txt').getData();
// Load bundle into cache.
LoadBundleTask task = FirebaseFirestore.instance.loadBundle(buffer);
// Wait until all info has been loaded into cache!
await task.stream.last;

查看浏览器的控制台我得到了这个:

@firebase/firestore:Firestore (8.10.0):SyncEngine 加载包失败,参数无效:0

捆绑文本文件正在从 Firebase 存储中正常加载并移交给 loadBundle() 函数。 一旦到达

await task.stream.last

它失败并给出上述错误。

通常,一旦加载了捆绑包,我就会对数据进行操作,但它甚至不会走到这一步。

await FirebaseFirestore.instance
        .namedQueryGet('latest-company',
            options: const GetOptions(source: Source.cache))
        .then((snaps) {
      for (var doc in snaps.docs) {
        Map dic = doc.data();
}});

如前所述,它在我笔记本电脑上的模拟器中运行良好,但一旦部署到网络上,它就会失败。

在我的 index.html 中,我使用如下库。

  <!-- The core Firebase JS SDK is always required and must be listed first -->
  <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
  <!-- If you enabled Analytics in your project, add the Firebase SDK for Analytics -->
  <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-analytics.js"></script>
  <!-- Add Firebase products that you want to use -->
  <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-auth.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-firestore.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-storage.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-functions.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-messaging.js"></script>

关注:

  <script>
    // Initialize Firebase
    var firebaseConfig = {
      ...
    };
    // Initialize Firebase
    firebase.initializeApp(firebaseConfig);
    firebase.analytics();
    // workaround for case when adblock blocks firebase analytics
    if (!firebase.analytics || !navigator.cookieEnabled) {
      firebase.analytics = function () { };
    }
  </script>

【问题讨论】:

    标签: firebase flutter google-cloud-firestore bundle flutter-web


    【解决方案1】:

    应该将 index.html 文件中的脚本与可用的库 here 进行比较。 此处包含的脚本标签在脚本标签中不包含 defer,您可能需要它来解决您的问题,例如。

    <script defer src=...>
    

    【讨论】:

    • 我没有在我的 index.html 中使用任何延迟
    猜你喜欢
    • 2020-11-01
    • 2021-07-19
    • 2020-10-03
    • 2021-07-14
    • 1970-01-01
    • 2021-09-27
    • 2020-09-06
    • 2023-03-10
    • 2019-03-13
    相关资源
    最近更新 更多