Switch.adaptive constructor
- Key? key,
- required bool value,
- required ValueChanged<
bool> ? onChanged, - Color? activeColor,
- Color? activeTrackColor,
- Color? inactiveThumbColor,
- Color? inactiveTrackColor,
- ImageProvider<
Object> ? activeThumbImage, - ImageErrorListener? onActiveThumbImageError,
- ImageProvider<
Object> ? inactiveThumbImage, - ImageErrorListener? onInactiveThumbImageError,
- MaterialTapTargetSize? materialTapTargetSize,
- MaterialStateProperty<
Color?> ? thumbColor, - MaterialStateProperty<
Color?> ? trackColor, - MaterialStateProperty<
Color?> ? trackOutlineColor, - MaterialStateProperty<
double?> ? trackOutlineWidth, - MaterialStateProperty<
Icon?> ? thumbIcon, - DragStartBehavior dragStartBehavior = DragStartBehavior.start,
- MouseCursor? mouseCursor,
- Color? focusColor,
- Color? hoverColor,
- MaterialStateProperty<
Color?> ? overlayColor, - double? splashRadius,
- FocusNode? focusNode,
- ValueChanged<
bool> ? onFocusChange, - bool autofocus = false,
- EdgeInsetsGeometry? padding,
- bool? applyCupertinoTheme,
Creates an adaptive Switch based on whether the target platform is iOS or macOS, following Material design's Cross-platform guidelines.
Creates a switch that looks and feels native when the ThemeData.platform is iOS or macOS, otherwise a Material Design switch is created.
To provide a custom switch theme that's only used by this factory
constructor, pass a custom Adaptation<SwitchThemeData>
class to the
adaptations
parameter of ThemeData. This can be useful in situations
where you don't want the overall ThemeData.switchTheme to apply when
this adaptive constructor is used.
To create a local project with this code sample, run:
flutter create --sample=material.Switch.Switch.adaptive.1 mysample
The target platform is based on the current Theme: ThemeData.platform.
Implementation
const Switch.adaptive({
super.key,
required this.value,
required this.onChanged,
this.activeColor,
this.activeTrackColor,
this.inactiveThumbColor,
this.inactiveTrackColor,
this.activeThumbImage,
this.onActiveThumbImageError,
this.inactiveThumbImage,
this.onInactiveThumbImageError,
this.materialTapTargetSize,
this.thumbColor,
this.trackColor,
this.trackOutlineColor,
this.trackOutlineWidth,
this.thumbIcon,
this.dragStartBehavior = DragStartBehavior.start,
this.mouseCursor,
this.focusColor,
this.hoverColor,
this.overlayColor,
this.splashRadius,
this.focusNode,
this.onFocusChange,
this.autofocus = false,
this.padding,
this.applyCupertinoTheme,
}) : assert(activeThumbImage != null || onActiveThumbImageError == null),
assert(inactiveThumbImage != null || onInactiveThumbImageError == null),
_switchType = _SwitchType.adaptive;