thumbColor property Null safety
final
The color of this Switch's thumb.
Resolved in the following states:
This example resolves the thumbColor based on the current
MaterialState of the Switch, providing a different
Color
when it is
MaterialState.disabled.
Switch(
value: true,
onChanged: (_) => true,
thumbColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return Colors.orange.withOpacity(.48);
}
return Colors.orange;
}),
)
If null, then the value of activeColor is used in the selected state and inactiveThumbColor in the default state. If that is also null, then the value of SwitchThemeData.thumbColor is used. If that is also null, then the following colors are used:
State | Light theme | Dark theme |
---|---|---|
Default | Colors.grey.shade50 | Colors.grey.shade400 |
Selected | ThemeData.toggleableActiveColor | ThemeData.toggleableActiveColor |
Disabled | Colors.grey.shade400 | Colors.grey.shade800 |
Implementation
final MaterialStateProperty<Color?>? thumbColor;