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

Flutter 'package:flutter/src/painting/_network_image_io.dart': Failed assertion: line 26 pos 16: 'url != null': is not true

我想显示来自 Firestore 的用户图像。但是显示错误。显示带有此错误的图像。'package:flutter/src/painting/_network_image_io.dart':断言失败:第 26 行第 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),
            ),
          ),

请像这样设置你的字符串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),
                  )),

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

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)