thumbColor property
The color of this Switch's thumb.
Resolved in the following states:
This example resolves the thumbColor based on the current WidgetState of the Switch, providing a different Color when it is WidgetState.disabled.
Switch(
value: _value,
// If `onChanged` is null, this switch is disabled.
// If `onChanged` is not null, this switch is enabled.
onChanged: _nullableOnChanged,
thumbColor: WidgetStateProperty.resolveWith<Color>((
Set<WidgetState> states,
) {
if (states.contains(WidgetState.disabled)) {
return Colors.orange.withValues(alpha: .48);
}
return Colors.orange;
}),
)
If null, then the value of activeThumbColor 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 | ColorScheme.secondary | ColorScheme.secondary |
| Disabled | Colors.grey.shade400 |
Colors.grey.shade800 |
Implementation
final WidgetStateProperty<Color?>? thumbColor;