我有这个主题我提供给我的MaterialApp
的数据
ThemeData get themeData => ThemeData(
...
chipTheme: _chipTheme(),
);
字符串
其中_chipTheme
只是一个自定义的ChipThemeData
,它具有labelStyle
属性:
labelStyle: MaterialStateTextStyle.resolveWith(
(states) {
TextStyle? textStyle;
if (states.contains(MaterialState.disabled)) {
textStyle = ...
}
else {
....
}
return textStyle ?? const TextStyle();
},
),
型
问题是labelStyle
没有被应用,在resolveWith
方法中设置断点/打印语句,我可以看到它没有被调用,我做错了什么,我如何根据芯片的状态设置labelStyle
(选择/禁用/等...)
编辑1
我知道我通常可以传递TextStyle
而不是MaterialStateTextStyle
,但这不会解决问题,因为我需要根据芯片的MaterialState
更改TextStyle
1条答案
按热度按时间oymdgrw71#
字符串
如果您将onPressed从Windows Chip中删除,它应该跳转到禁用状态。
如文档中所述,您可以处理以下状态:
如果TextStyle.color是MaterialStateProperty,则MaterialStateProperty.resolve用于以下MaterialStates:
MaterialState.disabled.MaterialState.selected.MaterialState.hovered.MaterialState.focused.MaterialState.pressed.