thumbIcon property
The icon to use on the thumb of this switch
Resolved in the following states:
This example resolves the thumbIcon based on the current WidgetState of the Switch, providing a different Icon when it is WidgetState.disabled.
Switch(
value: true,
onChanged: (bool value) { },
thumbIcon: WidgetStateProperty.resolveWith<Icon?>((Set<WidgetState> states) {
if (states.contains(WidgetState.disabled)) {
return const Icon(Icons.close);
}
return null; // All other states will use the default thumbIcon.
}),
)
If null, then the value of SwitchThemeData.thumbIcon is used. If this is also null, then the Switch does not have any icons on the thumb.
Implementation
// TODO(framework): Add unit tests to this code snippet.
// https://github.com/flutter/flutter/issues/188530
///
/// This example resolves the [thumbIcon] based on the current
/// [WidgetState] of the [Switch], providing a different [Icon] when it is
/// [WidgetState.disabled].
///
/// ```dart
/// Switch(
/// value: true,
/// onChanged: (bool value) { },
/// thumbIcon: WidgetStateProperty.resolveWith<Icon?>((Set<WidgetState> states) {
/// if (states.contains(WidgetState.disabled)) {
/// return const Icon(Icons.close);
/// }
/// return null; // All other states will use the default thumbIcon.
/// }),
/// )
/// ```
///
/// </callout-box>
/// {@endtemplate}
///
/// If null, then the value of [SwitchThemeData.thumbIcon] is used. If this is also null,
/// then the [Switch] does not have any icons on the thumb.
final WidgetStateProperty<Icon?>? thumbIcon;