概述

#

现在,当 `Checkbox` 未选中时,`Checkbox.fillColor` 会应用于复选框的背景。

背景

#

以前,当 `Checkbox` 未选中且背景透明时,`Checkbox.fillColor` 会应用于复选框的边框。在此更改后,当 `Checkbox` 未选中时,`Checkbox.fillColor` 会应用于复选框的背景,而边框使用 `Checkbox.side` 的颜色。

变更说明

#

现在,当 `Checkbox` 未选中时,`Checkbox.fillColor` 会应用于复选框的背景,而不是用作边框颜色。

迁移指南

#

更新后的 `Checkbox.fillColor` 行为会将填充颜色应用于未选中状态下复选框的背景。要获得之前的行为,请在未选中状态下将 `Checbox.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