我已经检查了无效的值,但仍然有错误,说我没有检查

发布于 2025-02-08 21:31:02 字数 259 浏览 3 评论 0原文

我已经在使用该值之前已经进行了零检查“在此处输入图像说明”

enter image description hereI already have a null check before using the value but it still give me errorenter image description here

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

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

发布评论

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

评论(2

寄居者 2025-02-15 21:31:02

您可以在其后面放置,以表明您确定它不能为空,因此,就像

for (final value in widget.details.data.productPriceObjs!) {

您不喜欢使用一样,您可以以

var objects = widget.details.data.productPriceObjs;
if (objects != null) {
  for (final value in objects) {
  
  }
}

某种方式编写编译器当检查中没有“嵌套”时,它很好

You can put an ! behind it to indicate you are sure it can't be null, so like

for (final value in widget.details.data.productPriceObjs!) {

If you don't like using ! you can alternatively write

var objects = widget.details.data.productPriceObjs;
if (objects != null) {
  for (final value in objects) {
  
  }
}

Somehow the compiler is fine with it when there isn't "nesting" in the check

苹果你个爱泡泡 2025-02-15 21:31:02

put widget.details.data.productpriceobjs后面标记,以确保编译该值不为NULL,

以获取有关NULL安全的更多详细信息在这里阅读

Put ! mark behind widget.details.data.productPriceObjs to make sure to compiler that this value is not null

For more details about null safety read here

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