CupertinoSwitch constructor

const CupertinoSwitch({
  1. Key? key,
  2. required bool value,
  3. required ValueChanged<bool>? onChanged,
  4. @Deprecated('Use activeTrackColor instead. ' 'This feature was deprecated after v3.24.0-0.2.pre.') Color? activeColor,
  5. @Deprecated('Use inactiveTrackColor instead. ' 'This feature was deprecated after v3.24.0-0.2.pre.') Color? trackColor,
  6. Color? activeTrackColor,
  7. Color? inactiveTrackColor,
  8. Color? thumbColor,
  9. Color? inactiveThumbColor,
  10. bool? applyTheme,
  11. Color? focusColor,
  12. Color? onLabelColor,
  13. Color? offLabelColor,
  14. ImageProvider<Object>? activeThumbImage,
  15. ImageErrorListener? onActiveThumbImageError,
  16. ImageProvider<Object>? inactiveThumbImage,
  17. ImageErrorListener? onInactiveThumbImageError,
  18. WidgetStateProperty<Color?>? trackOutlineColor,
  19. WidgetStateProperty<double?>? trackOutlineWidth,
  20. WidgetStateProperty<Icon?>? thumbIcon,
  21. WidgetStateProperty<MouseCursor>? mouseCursor,
  22. FocusNode? focusNode,
  23. ValueChanged<bool>? onFocusChange,
  24. bool autofocus = false,
  25. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
})

Creates an iOS-style switch.

The following arguments are required:

  • value determines whether this switch is on or off.
  • onChanged is called when the user toggles the switch on or off.

The dragStartBehavior parameter defaults to DragStartBehavior.start.

Implementation

const CupertinoSwitch({
  super.key,
  required this.value,
  required this.onChanged,
  @Deprecated(
    'Use activeTrackColor instead. '
    'This feature was deprecated after v3.24.0-0.2.pre.'
  )
  Color? activeColor,
  @Deprecated(
    'Use inactiveTrackColor instead. '
    'This feature was deprecated after v3.24.0-0.2.pre.'
  )
  Color? trackColor,
  Color? activeTrackColor,
  Color? inactiveTrackColor,
  this.thumbColor,
  this.inactiveThumbColor,
  this.applyTheme,
  this.focusColor,
  this.onLabelColor,
  this.offLabelColor,
  this.activeThumbImage,
  this.onActiveThumbImageError,
  this.inactiveThumbImage,
  this.onInactiveThumbImageError,
  this.trackOutlineColor,
  this.trackOutlineWidth,
  this.thumbIcon,
  this.mouseCursor,
  this.focusNode,
  this.onFocusChange,
  this.autofocus = false,
  this.dragStartBehavior = DragStartBehavior.start,
})  : assert(activeThumbImage != null || onActiveThumbImageError == null),
      assert(inactiveThumbImage != null || onInactiveThumbImageError == null),
      assert(activeTrackColor == null || activeColor == null),
      assert(inactiveTrackColor == null || trackColor == null),
      activeTrackColor = activeTrackColor ?? activeColor,
      inactiveTrackColor = inactiveTrackColor ?? trackColor;