Skip to main content

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:

  1. Using ThemeData's ColorScheme.secondary.
  2. Using components themes SwitchThemeData, ListTileThemeData, CheckboxThemeData, and RadioThemeData.
  3. By customizing the widget's color properties.

Code before migration:

dart
MaterialApp(
  theme: ThemeData(toggleableActiveColor: myColor),
  // ...
);

Code after migration:

dart
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: