Switch.adaptive constructor

const Switch.adaptive({
  1. Key? key,
  2. required bool value,
  3. required ValueChanged<bool>? onChanged,
  4. Color? activeColor,
  5. Color? activeTrackColor,
  6. Color? inactiveThumbColor,
  7. Color? inactiveTrackColor,
  8. ImageProvider<Object>? activeThumbImage,
  9. ImageErrorListener? onActiveThumbImageError,
  10. ImageProvider<Object>? inactiveThumbImage,
  11. ImageErrorListener? onInactiveThumbImageError,
  12. MaterialTapTargetSize? materialTapTargetSize,
  13. MaterialStateProperty<Color?>? thumbColor,
  14. MaterialStateProperty<Color?>? trackColor,
  15. MaterialStateProperty<Color?>? trackOutlineColor,
  16. MaterialStateProperty<double?>? trackOutlineWidth,
  17. MaterialStateProperty<Icon?>? thumbIcon,
  18. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  19. MouseCursor? mouseCursor,
  20. Color? focusColor,
  21. Color? hoverColor,
  22. MaterialStateProperty<Color?>? overlayColor,
  23. double? splashRadius,
  24. FocusNode? focusNode,
  25. ValueChanged<bool>? onFocusChange,
  26. bool autofocus = false,
  27. 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.

This sample shows how to create and use subclasses of Adaptation that define adaptive SwitchThemeDatas.
link

To create a local project with this code sample, run:
flutter create --sample=material.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.applyCupertinoTheme,
})  : assert(activeThumbImage != null || onActiveThumbImageError == null),
      assert(inactiveThumbImage != null || onInactiveThumbImageError == null),
      _switchType = _SwitchType.adaptive;