Flutter 应用程序圆形头像中的 Firebase 存储中的图像未显示

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

我正在获取图像网址,但在网络图像或圆圈头像图像中未加载

这是我的代码:(从 Firebase 获取 URL:)

String IMGURL = '';
_firebaseFirestore
    .collection("Users")
    .doc(_auth.currentUser!.uid.toString())
    .get()
    .then(
  (snapshot) {
    setState(() {
      IMGURL = snapshot.data()!['PROFILE_IMG'];
      encodedURL = Uri.encodeFull(IMGURL);
      print(IMGURL);
    });
  },
);

这就是我显示图像的方式:

IMGURL != null
              ? CircleAvatar(
                radius: 18,
                backgroundImage: NetworkImage(IMGURL),)
              : IconButton(
                  onPressed: () {
                    setState(() {
                      currentPage = 5;
                    });
                  },
flutter firebase google-cloud-firestore
1个回答
2
投票

NetworkImage
中传递以下内容:

NetworkImage(Uri.encodeFull(IMGURL))

您需要传递编码后的uri,以便可以读取并显示它。目前您只是将其分配给变量

encodedURL

此外,最好将图像存储在Firebase Storage中,然后您可以轻松接收网址并显示它。

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