【发布时间】:2021-06-09 17:26:32
【问题描述】:
GetPhotoUrlStream 提供存储在我的 Cloud Firebase FireStore 中的个人资料照片 (data['profilePhoto']) 的 Url 流。然后被networkimage用来显示个人资料照片(圆形头像)
class GetUserPhotoUrlStream extends StatelessWidget {
final String documentId; // This is your User UID
GetUserPhotoUrlStream(this.documentId);
@override
Widget build(BuildContext context) {
DocumentReference users = FirebaseFirestore.instance.collection('users').doc(documentId);
return StreamBuilder<DocumentSnapshot>(
stream: users.snapshots(),
builder: (BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.hasError) {
return Image.asset('assets/images/NouserImage.png');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
}
Map<String, dynamic> data = snapshot.data.data();
return CircleAvatar(
maxRadius: 80,
backgroundColor: Colors.grey,
child: ClipOval(child: FadeInImage(placeholder: AssetImage('assets/images/NouserImage.png'),image: NetworkImage("${data['profilePhoto']}"),),),
);
},
);
}
}
removeUserPhotoUrl 将 GetUserPhotoUrlStream 正在使用的“profilePhoto”更新为 null。
Future<void> removeUserPhotoUrl(BuildContext context) async
{
var user = _auth.currentUser;
DocumentReference users = FirebaseFirestore.instance.collection('users').doc(user.uid);
users.update({'profilePhoto':null}).then((_){
Navigator.pop(context);
});
await deleteUserImage(context);
notifyListeners();
}
当使用 removeUserPhotoUrl 将 data['profilePhoto'] 的值设为 null 时,它应该显示占位符图像,它提供了一个assetImage,而不是它给出了一个错误
错误信息
====================================================================================================
======== Exception caught by image resource service ================================================
Invalid argument(s): No host specified in URI file:///null
====================================================================================================
此外,当应用程序处于 HotReload 或 HotRestart 时,错误消失并开始向我显示 PlaceHolder(资产图像)
请帮助。我想在“profilePhoto”变为空时显示占位符(资产图像)
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore setstate