# Updated `Checkbox.fillColor` behavior

> Improved `Checkbox.fillColor` behavior applies the fill color to the background when the checkbox is unselected.




:::important
These breaking change docs are accurate, as of the release
under which they are published. Over time, the
workarounds described here might become inaccurate.
We don't, in general, keep these breaking change docs up
to date as of each release.

这些破坏性改动文档的准确性仅限于其发布时对应的版本。
随着时间的推移，文档中描述的方案可能会逐渐失效。
通常情况下，我们不会在每次发布新版本时都对这些文档进行同步更新。

The [breaking change index file](/release/breaking-changes)
lists the docs created for each release.

[破坏性改动列表](/release/breaking-changes) 
列出了每个版本的文档。

:::


## Summary

The `Checkbox.fillColor` is now applied to the checkbox's background when
the checkbox is unselected.

## Context

Previously, the `Checkbox.fillColor` was applied to the checkbox's border
when the checkbox was unselected and its background was transparent.
With this change, the `Checkbox.fillColor` is applied to the checkbox's
background and the border uses the `Checkbox.side` color when the checkbox
is unselected.

## Description of change

The `Checkbox.fillColor` is now applied to the checkbox's background when
the checkbox is unselected instead of being used as the border color.

## Migration guide

The updated `Checkbox.fillColor` behavior applies the fill color to the
checkbox's background in the unselected state. To get the previous behavior,
set `Checkbox.fillColor` to `Colors.transparent` in the unselected state and
set `Checkbox.side` to the desired color.

If you use the `Checkbox.fillColor` property to customize the checkbox.

Code before migration:

```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,
),
```

Code after migration:

```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,
),
```

If you use the `CheckboxThemeData.fillColor` property to customize the checkbox.

Code before migration:

```dart
checkboxTheme: CheckboxThemeData(
  fillColor: MaterialStateProperty.resolveWith((states) {
    if (!states.contains(MaterialState.selected)) {
      return Colors.red;
    }
    return null;
  }),
),
```

Code after migration:

```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),
),
```

## Timeline

Landed in version: 3.10.0-17.0.pre<br>
In stable release: 3.13.0

## References

API documentation:

* [`Checkbox.fillColor`][]

Relevant issues:

* [Add `backgroundColor` to `Checkbox` and `CheckboxThemeData`][]

Relevant PRs:

* [`Checkbox.fillColor` should be applied to checkbox's background color when it is unchecked.][]

[`Checkbox.fillColor`]: https://api.flutter-io.cn/flutter/material/Checkbox/fillColor.html

[Add `backgroundColor` to `Checkbox` and `CheckboxThemeData`]: https://github.com/flutter/flutter/issues/123386
[`Checkbox.fillColor` should be applied to checkbox's background color when it is unchecked.]: https://github.com/flutter/flutter/pull/125643

