ThemeData's toggleableActiveColor property has been deprecated
Summary
#The Material widgets Switch
, SwitchListTile
, Checkbox
,
CheckboxListTile
, Radio
, RadioListTile
now use
ColorScheme.secondary
color for their toggleable widget.
ThemeData.toggleableActiveColor
is deprecated and will eventually be removed.
Context
#The migration of widgets that depend on ThemeData.toggleableActiveColor
to ColorScheme.secondary
caused the toggleableActiveColor
property
to be unnecessary. This property will eventually be removed, as per Flutter's
deprecation policy.
Description of change
#The widgets using ThemeData.toggleableActiveColor
color for the
active/selected state now use ColorScheme.secondary
.
Migration guide
#Toggleable widgets' active/selected color can generally be customized in 3 ways:
- Using ThemeData's
ColorScheme.secondary
. - Using components themes
SwitchThemeData
,ListTileThemeData
,CheckboxThemeData
, andRadioThemeData
. - By customizing the widget's color properties.
Code before migration:
MaterialApp(
theme: ThemeData(toggleableActiveColor: myColor),
// ...
);
Code after migration:
final ThemeData theme = ThemeData();
MaterialApp(
theme: theme.copyWith(
switchTheme: SwitchThemeData(
thumbColor: MaterialStateProperty.resolveWith<Color?>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return null;
}
if (states.contains(MaterialState.selected)) {
return myColor;
}
return null;
}),
trackColor: MaterialStateProperty.resolveWith<Color?>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return null;
}
if (states.contains(MaterialState.selected)) {
return myColor;
}
return null;
}),
),
radioTheme: RadioThemeData(
fillColor: MaterialStateProperty.resolveWith<Color?>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return null;
}
if (states.contains(MaterialState.selected)) {
return myColor;
}
return null;
}),
),
checkboxTheme: CheckboxThemeData(
fillColor: MaterialStateProperty.resolveWith<Color?>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return null;
}
if (states.contains(MaterialState.selected)) {
return myColor;
}
return null;
}),
),
),
//...
)
Timeline
#In stable release: 3.7
References
#API documentation:
Relevant issues:
Relevant PRs:
除非另有说明,本文档之所提及适用于 Flutter 的最新稳定版本,本页面最后更新时间: 2024-04-04。 查看文档源码 或者 为本页面内容提出建议。