flutter - 错误:必须向文本小部件提供非空字符串
问题描述
我在运行代码时遇到问题。我看到这个错误:
Text(product.description,
style: TextStyle(
color: Colors.black,
),
和错误:
"The following assertion was thrown building DescriptionPage(dirty):
A non-null String must be provided to a Text widget.
'package:flutter/src/widgets/text.dart':
Failed assertion: line 285 pos 10: 'data != null'"
解决方案
Text((product!=null && product.description!=null)?product.description:'',
style: TextStyle(
color: Colors.black,
),
推荐阅读
- python - 如何在 Pandas DataFrame 数据透视表的 Matplotlib 线图中显示更多类别?
- python - 为什么我在赋值之前会引用局部变量?
- terraform - 如何将字符串添加到 Terraform 中的变量?
- javascript - 将箭头函数添加到以行和列为参数的表格单元格
- java - Spring Data r2dbc - 实体继承
- vb.net - vb.net 检测表单上的按键
- javascript - 如何将 THIS 关键字用于在 JQUERY 中没有操作的函数
- c - 检查 NULL 返回分段错误
- docker - docker compose 延迟容器构建和启动
- c - 颜色一个单元格ncurses