首页 > 解决方案 > 错误:必须向文本小部件提供非空字符串

问题描述

我在运行代码时遇到问题。我看到这个错误:

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'"

标签: flutter

解决方案


Text((product!=null && product.description!=null)?product.description:'',
          style: TextStyle(
              color: Colors.black,
          ),

推荐阅读