flutter - 在空值检查中操作数不能为空
问题描述
我想检查 if text2!
is not null
,然后将 的 设置为height
变量SizedBox
中的值height
。如果是,则将的null
设置height
为。SizedBox
0
错误:操作数不能为空,因此条件始终为真。
代码
double height = 10;
SizedBox(
height: widget.text2! != null ? height : 0,
),
解决方案
通过使用!
你说那text2
不是空的。只需省略!
.
SizedBox(height: widget.text2 != null ? height : 0,),
推荐阅读
- linux - 找不到框架“Microsoft.AspNetCore.App”,版本“5.0.0”。当它安装并在 $PATH 中时
- swift - 如何限制选择器视图中显示的行数?
- javascript - WebRTC,getDisplayMedia() 不会从远程流中捕获声音
- c++ - 对 boost::serialization 的未定义引用
- vue.js - 如何在 Vue 3 组件中使用 Vuex 4 状态数据作为另一个调度的有效负载?
- android - 在 Android 中使用 Kotlin Coroutines 保存文件显示不适当的阻塞方法调用
- javascript - 使用给定条件验证字符串
- javascript - React 中的 Axios/Backend 会在一段时间后停止工作且没有错误
- c# - 带编码的 Asp net core 文件结果
- python - multiprocessing.Pipe() 返回的连接对象是否在不同进程中共享?