Flutter Web 不显示 Firebase 存储中的 NetworkImages,但在 Android 模拟器上完美运行

问题描述 投票:0回答:2

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

代码:

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 上运行。任何帮助将不胜感激,谢谢。

firebase flutter google-cloud-firestore
2个回答
0
投票

这个问题有更新吗? 版本面临同样的问题: 颤振 SDK:“3.1.0” firebase_存储:^11.6.0


-2
投票

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

//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

© www.soinside.com 2019 - 2024. All rights reserved.