操作数可以为null,因此条件始终是正确的。删除条件

发布于 2025-02-01 11:31:07 字数 300 浏览 2 评论 0原文

我不断收到此警告,我不确定如何解决。如果您可以的话,请帮助 以下是代码的摘录

String imageUrl = '';

CircleAvatar(
     backgroundColor: Colors.white70,
     backgroundImage: imageUrl != null
    ? Image.network(imageUrl).image
      : AssetImage(ProjectImages.placeholder),
        minRadius: 50.0,
     ),

I keep getting this warning and I am unsure how to resolve it. Help if u can please
Below is the excerpt of the code

String imageUrl = '';

CircleAvatar(
     backgroundColor: Colors.white70,
     backgroundImage: imageUrl != null
    ? Image.network(imageUrl).image
      : AssetImage(ProjectImages.placeholder),
        minRadius: 50.0,
     ),

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

櫻之舞 2025-02-08 11:31:07

您之所以会得到此警告,是因为您正在声明带有和空字符串的变量“ imageUrl”

注意:空字符串和空物都不相同。因此,要摆脱此警告,您必须使您的可变无效

String? imageUrl;

CircleAvatar(
     backgroundColor: Colors.white70,
     backgroundImage: imageUrl != null
    ? Image.network(imageUrl).image
      : AssetImage(ProjectImages.placeholder),
        minRadius: 50.0,
     ),

您的警告将消失:)

You are getting this warning because you are declaring your variable "imageUrl" with and empty String.

Note: Empty string and null both are not same they are different. So, to get rid of this warning you have to make your variable nullable like this

String? imageUrl;

CircleAvatar(
     backgroundColor: Colors.white70,
     backgroundImage: imageUrl != null
    ? Image.network(imageUrl).image
      : AssetImage(ProjectImages.placeholder),
        minRadius: 50.0,
     ),

Your warning will be gone :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文