firebase - Flutter Web 不显示来自 Firebase 存储的网络图像,但是在 Android 模拟器上完美运行

标签 firebase flutter google-cloud-firestore

如标题所示,我正在将我的应用程序部署到 Flutter Web,并显示来自 Firebase 存储的图片。在android模拟器上测试时,它完美运行并显示所有图像而没有错误。但是,当我将它部署到我的 Web 应用程序时,由于某种原因根本不显示图像。下面我添加了相关的代码片段,它显示了我如何显示来自 Firebase 的图片(同样,它在 Android 模拟器上工作得很好)以及网络应用程序在尝试显示图片时出现的错误。

代码:

void checkImages() async {
    FirebaseFirestore.instance
        .collection("uploads")
        .where('username', isEqualTo: Constants.myName)
        .get()
        .then((querySnapshot) {
      querySnapshot.docs.forEach((result) {
        FirebaseFirestore.instance
            .collection("uploads")
            .doc(result.id)
            .collection("images")
            .get()
            .then((querySnapshot) {
          querySnapshot.docs.forEach((result) async {
            imageCount++;
            final ref =
                FirebaseStorage.instance.ref().child(result.data()['imageid']);
            url = await ref.getDownloadURL();
            setState(() {
              printImages();
            });
          });
        });
      });
    });
  }

  printImages() {
    return List.generate(imageCount, (index) {
      return GestureDetector(
        onTap: () {
          print( "hello");
        },
        child: Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.all(
              Radius.circular(10),
            ),
          ),
          child: Image.network(
            url.toString(),
            fit: BoxFit.cover,
          ),
        ),
      );
    });
  } 

网络控制台错误:

main.dart.js?version=19:3082 Uncaught MissingPluginException(No implementation found for method StorageReference#getDownloadUrl on channel plugins.flutter.io/firebase_storage)
    at Object.a (https://social-io-102b4.firebaseapp.com/main.dart.js?version=19:3082:3)
    at https://social-io-102b4.firebaseapp.com/main.dart.js?version=19:53813:15
    at adv.a (https://social-io-102b4.firebaseapp.com/main.dart.js?version=19:4517:71)
    at adv.$2 (https://social-io-102b4.firebaseapp.com/main.dart.js?version=19:30063:23)
    at acI.$1 (https://social-io-102b4.firebaseapp.com/main.dart.js?version=19:30055:30)
    at No.mY (https://social-io-102b4.firebaseapp.com/main.dart.js?version=19:31072:40)
    at a82.$0 (https://social-io-102b4.firebaseapp.com/main.dart.js?version=19:30474:11)
    at Object.rs (https://social-io-102b4.firebaseapp.com/main.dart.js?version=19:4637:40)
    at a1.nL (https://social-io-102b4.firebaseapp.com/main.dart.js?version=19:30390:3)
    at a7V.$0 (https://social-io-102b4.firebaseapp.com/main.dart.js?version=19:30432:22)

除此之外,我非常确定我已正确安装所有插件,因为它适用于 Android。任何帮助将不胜感激,谢谢。

最佳答案

请尝试将此脚本标记 添加到您的 index.html 中,在您使用 Firebase 凭据对其进行初始化后(当您在 Firebase 中添加新的网络应用程序时会获得它们)

//import the Firestore plugin
<script src="https://www.gstatic.com/firebasejs/8.2.10/firebase-firestore.js"></script>

看看这个网站,看看你可能想要导入的所有插件:

https://firebase.google.com/docs/web/setup#expandable-8

关于firebase - Flutter Web 不显示来自 Firebase 存储的网络图像,但是在 Android 模拟器上完美运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66492373/

相关文章:

javascript - Firebase电子邮件/密码身份验证未注册用户

javascript - admin.auth().setCustomUserClaims "is not a function"

android - 找不到 com.google.firebase-core :17. 0.1:

php - 如何通过 PHP 将照片从 Flutter App 上传到服务器?

google-cloud-firestore - Firestore 规则 get()/exists() 不起作用

firebase - 在Dart中从Cloud_Firestore获取 bool 状态

ios - 未识别的 CFRunLoopRun 崩溃报告问题

firebase - 解析错误 : 'import' and 'export' may appear only with 'sourceType: module'

javascript - 带有自定义声音的推送通知未显示在 iOS 中

java - 如何将 .addSnapShotListener 设置为 fragment 中的集合引用