`Checkbox.fillColor` 行为更新
概述
#当复选框未选中时,Checkbox.fillColor
现在应用于复选框的背景。
背景
#此前,当复选框未选中且背景透明时,Checkbox.fillColor
会应用于复选框的边框。此更改后,当复选框未选中时,Checkbox.fillColor
将应用于复选框的背景,而边框则使用 Checkbox.side
颜色。
变更说明
#当复选框未选中时,Checkbox.fillColor
现在应用于复选框的背景,而不是用作边框颜色。
迁移指南
#更新后的 Checkbox.fillColor
行为在未选中状态下将填充颜色应用于复选框的背景。要恢复之前的行为,请在未选中状态下将 Checkbox.fillColor
设置为 Colors.transparent
,并将 Checkbox.side
设置为所需的颜色。
如果您使用 Checkbox.fillColor
属性自定义复选框。
迁移前的代码
dart
Checkbox(
fillColor: MaterialStateProperty.resolveWith((states) {
if (!states.contains(MaterialState.selected)) {
return Colors.red;
}
return null;
}),
value: _checked,
onChanged: _enabled
? (bool? value) {
setState(() {
_checked = value!;
});
}
: null,
),
迁移后的代码
dart
Checkbox(
fillColor: MaterialStateProperty.resolveWith((states) {
if (!states.contains(MaterialState.selected)) {
return Colors.transparent;
}
return null;
}),
side: const BorderSide(color: Colors.red, width: 2),
value: _checked,
onChanged: _enabled
? (bool? value) {
setState(() {
_checked = value!;
});
}
: null,
),
如果您使用 CheckboxThemeData.fillColor
属性自定义复选框。
迁移前的代码
dart
checkboxTheme: CheckboxThemeData(
fillColor: MaterialStateProperty.resolveWith((states) {
if (!states.contains(MaterialState.selected)) {
return Colors.red;
}
return null;
}),
),
迁移后的代码
dart
checkboxTheme: CheckboxThemeData(
fillColor: MaterialStateProperty.resolveWith((states) {
if (!states.contains(MaterialState.selected)) {
return Colors.transparent;
}
return null;
}),
side: const BorderSide(color: Colors.red, width: 2),
),
时间线
#发布版本:3.10.0-17.0.pre
在稳定版中发布: 3.13.0
参考资料
#API 文档
相关问题
相关 PR