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:
Unless stated otherwise, the documentation on this site reflects the latest stable version of Flutter. Page last updated on 2024-04-04. View source or report an issue.