Flutter PlutoGrid如何根据单元格值条件更改文本颜色?
解决Pluto Grid单元格根据值动态设置文本颜色的问题
问题出在你给TextStyle加了const修饰符——const要求所有参数必须是编译时常量,但你的textColor是根据单元格值动态计算的变量,不符合常量要求,所以报错。
只需去掉TextStyle前的const关键字即可解决:
PlutoColumn( title: '% Change', field: 'percentChange', type: PlutoColumnType.number(), readOnly: true, titleTextAlign: PlutoColumnTextAlign.right, textAlign: PlutoColumnTextAlign.right, renderer: (rendererContext) { Color textColor = rendererContext.cell.value < 0 ? Colors.red : Colors.green; return Text( textAlign: TextAlign.right, rendererContext.cell.value.toString(), style: TextStyle( // 移除const修饰符 debugLabel: 'blackCupertino bodySmall', fontFamily: '.SF UI Text', color: textColor, decoration: TextDecoration.none, ), ); }, ),
修改后textColor就能根据单元格值动态切换,TextStyle也能正常使用动态参数。
内容的提问来源于stack exchange,提问作者Sami Tarazi
相关产品推荐
相关产品推荐

