首页 > 解决方案 > 在空值检查中操作数不能为空

问题描述

我想检查 if text2!is not null,然后将 的 设置为height变量SizedBox中的值height。如果是,则将的null设置height为。SizedBox0

错误:操作数不能为空,因此条件始终为真。

代码

double height = 10;

SizedBox(
            height: widget.text2! != null ? height : 0,
          ),

标签: flutter

解决方案


通过使用!你说那text2不是空的。只需省略!.

SizedBox(height: widget.text2 != null ? height : 0,),

推荐阅读