我正在获取图像网址,但在网络图像或圆圈头像图像中未加载
这是我的代码:(从 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;
});
},
在
NetworkImage
中传递以下内容:
NetworkImage(Uri.encodeFull(IMGURL))
您需要传递编码后的uri,以便可以读取并显示它。目前您只是将其分配给变量
encodedURL
。
此外,最好将图像存储在Firebase Storage中,然后您可以轻松接收网址并显示它。