trackOutlineColor property
The outline color of this Switch's track.
Resolved in the following states:
This example resolves the trackOutlineColor based on the current WidgetState of the Switch, providing a different Color when it is WidgetState.disabled.
Switch(
value: true,
onChanged: (bool value) { },
trackOutlineColor: WidgetStateProperty.resolveWith<Color?>((Set<WidgetState> states) {
if (states.contains(WidgetState.disabled)) {
return Colors.orange.withValues(alpha: .48);
}
return null; // Use the default color.
}),
)
In Material 3, the outline color defaults to transparent in the selected state and ColorScheme.outline in the unselected state. In Material 2, the Switch track has no outline by default.
Implementation
// TODO(framework): Add unit tests to this code snippet.
// https://github.com/flutter/flutter/issues/188530
///
/// This example resolves the [trackOutlineColor] based on the current
/// [WidgetState] of the [Switch], providing a different [Color] when it is
/// [WidgetState.disabled].
///
/// ```dart
/// Switch(
/// value: true,
/// onChanged: (bool value) { },
/// trackOutlineColor: WidgetStateProperty.resolveWith<Color?>((Set<WidgetState> states) {
/// if (states.contains(WidgetState.disabled)) {
/// return Colors.orange.withValues(alpha: .48);
/// }
/// return null; // Use the default color.
/// }),
/// )
/// ```
///
/// </callout-box>
/// {@endtemplate}
///
/// In Material 3, the outline color defaults to transparent in the selected
/// state and [ColorScheme.outline] in the unselected state. In Material 2,
/// the [Switch] track has no outline by default.
final WidgetStateProperty<Color?>? trackOutlineColor;