flutter - 无法无条件访问属性“xyz”,因为接收者可以为“null”
问题描述
我已将我的颤振项目版本升级到最新版本(2.5.3)。然后由于不受支持而发生了一些错误null-safety
。我已经修复了很多但仍然没有任何想法来修复以下null-safety
错误,
代码
itemBuilder: (context, suggestion) {
return ListTile(
subtitle: Text(
suggestion.stateA == null || suggestion.stateB == null
? '${suggestion.city}, ${suggestion.country}'
: '${suggestion.city}, ${suggestion.state}, ${suggestion.country}',
style: Theme.of(context).textTheme.bodyText,
),
);
}
错误
The property 'stateA' can't be unconditionally accessed because the receiver can be 'null'.
The property 'stateB' can't be unconditionally accessed because the receiver can be 'null'.
The property 'city' can't be unconditionally accessed because the receiver can be 'null'.
The property 'country' can't be unconditionally accessed because the receiver can be 'null'.
如何在代码上方添加检查空安全性?
我已经尝试使用!
&?
运算符,但它对我不起作用
(即suggestion!.state
)
解决方案
推荐阅读
- asp.net-core - 帐户锁定时间跨度溢出
- wordpress - 如何为 Wordpress 中的所有类别创建通用自定义主题页面
- python - 使用python的BDD中的步骤数据以及Scenario Outline之间的差异
- python - selenium 两个 xpath 测试合二为一
- css - 与输入字段内联的 Angular Material 微调器
- ubuntu - RabbitMQ 未启动“未能创建脏调度程序线程 0”
- php - 试图获取非对象的属性“(...)”
- r - 使用 sparklyr 计算订单统计信息(百分比)
- node.js - 在 node.js 项目中运行节点控制台是否会加载 package.json 中的所有依赖项?
- flutter - 从 Json 文件中获取数据但地图不起作用