Flutter 'package:flutter/src/painting/_network_image_io.dart':断言失败:第 26 行 pos 16:'url != null':不是真的

时间:2021-01-30 06:34:39

标签: firebase flutter dart flutter-web

我想显示来自 Firestore 的用户图像。但是显示错误。显示带有此错误的图像。'package:flutter/src/painting/_network_image_io.dart':断言失败:第 26 行 pos 16:'url != null':不正确。

class _ChatRoomListTileState extends State<ChatRoomListTile> {
  String profilePicUrl = "",
      name = "",
      username = "";

  getThisUserInfo() async {
    username =
        widget.chatRoomId.replaceAll(widget.myUserName, "").replaceAll("_", "");
    QuerySnapshot querySnapshot = await DatabaseMethods().getUserInfo(username);
    // print("something the data we are getting ${querySnapshot.docs[0].id}");
    name = "${querySnapshot.docs[0]["name"]}";
    profilePicUrl = querySnapshot.docs[0]["imgUrl"];
    setState(() {});
  }

@override
  void initState() {
    getThisUserInfo();
    super.initState();
  }

在一行中显示图像

ClipRRect(
            borderRadius: BorderRadius.circular(30),
            child: Image(
              height: 45.0,
              width: 45.0,
              image: NetworkImage(profilePicUrl) == null
                  ? AssetImage('assets/images/emoteU.png')
                  : NetworkImage(profilePicUrl),
            ),
          ),

enter image description here

2 个答案:

答案 0 :(得分:0)

请像这样设置你的字符串String profilePicUrl;试试这个可能对你有用

        ClipRRect(
            borderRadius: BorderRadius.circular(30),
            child: profilePicUrl.toString() == null
                ? const Image(
                    height: 45.0,
                    width: 45.0,
                    image: AssetImage('assets/images/emoteU.png'))
                : Image(
                    height: 45.0,
                    width: 45.0,
                    image: NetworkImage(profilePicUrl),
                  )),

答案 1 :(得分:0)

试试这个而不是图像小部件

ClipRRect(
            borderRadius: BorderRadius.circular(30),
            child:profilePicUrl==null? Image.asset(
              height: 45.0,
              width: 45.0,
            'assets/images/emoteU.png'
          ):
          Image.network(profilePicUrl,
                        height:45,
                        width:45)