【问题标题】:Flutter 'package:flutter/src/painting/_network_image_io.dart': Failed assertion: line 26 pos 16: 'url != null': is not trueFlutter 'package:flutter/src/painting/_network_image_io.dart':断言失败:第 26 行 pos 16:'url != null':不正确
【发布时间】:2021-05-04 00:17:54
【问题描述】:

我想显示来自 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),
            ),
          ),

【问题讨论】:

  • 不应该是image: NetworkImage(profilePicUrl) == null ? ...image: profilePicUrl == null ? ... 吗?
  • 我试过这个。但显示此错误type 'NetworkImage' is not a subtype of type 'String' where
  • 我在 huwai 设备上运行应用程序时遇到同样的错误。在其他设备上,应用程序运行正常,没有任何错误。我不确定为什么会收到此错误。
  • 请分享您的代码

标签: firebase flutter dart flutter-web


【解决方案1】:

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

【讨论】:

  • 显示此错误'package:flutter/src/painting/_network_image_io.dart': Failed assertion: line 26 pos 16: 'url != null': is not true.
  • @AzrafAlMonzim 请重新检查我的答案,如果您仍然遇到同样的错误,那么您的 image URL 为空
【解决方案2】:

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

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)

【讨论】:

    猜你喜欢
    • 2020-07-01
    • 1970-01-01
    • 2021-07-02
    • 2021-05-14
    • 2020-11-24
    • 2020-10-10
    • 2021-02-05
    • 2020-12-14
    • 2020-03-01
    相关资源
    最近更新 更多