SwitchListTile constructor

const SwitchListTile({
  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. MaterialStateProperty<Color?>? thumbColor,
  13. MaterialStateProperty<Color?>? trackColor,
  14. MaterialStateProperty<Color?>? trackOutlineColor,
  15. MaterialStateProperty<Icon?>? thumbIcon,
  16. MaterialTapTargetSize? materialTapTargetSize,
  17. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  18. MouseCursor? mouseCursor,
  19. MaterialStateProperty<Color?>? overlayColor,
  20. double? splashRadius,
  21. FocusNode? focusNode,
  22. ValueChanged<bool>? onFocusChange,
  23. bool autofocus = false,
  24. Color? tileColor,
  25. Widget? title,
  26. Widget? subtitle,
  27. bool isThreeLine = false,
  28. bool? dense,
  29. EdgeInsetsGeometry? contentPadding,
  30. Widget? secondary,
  31. bool selected = false,
  32. ListTileControlAffinity controlAffinity = ListTileControlAffinity.platform,
  33. ShapeBorder? shape,
  34. Color? selectedTileColor,
  35. VisualDensity? visualDensity,
  36. bool? enableFeedback,
  37. Color? hoverColor,
})

Creates a combination of a list tile and a switch.

The switch tile itself does not maintain any state. Instead, when the state of the switch changes, the widget calls the onChanged callback. Most widgets that use a switch will listen for the onChanged callback and rebuild the switch tile with a new value to update the visual appearance of the 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.

Implementation

const SwitchListTile({
  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.thumbColor,
  this.trackColor,
  this.trackOutlineColor,
  this.thumbIcon,
  this.materialTapTargetSize,
  this.dragStartBehavior = DragStartBehavior.start,
  this.mouseCursor,
  this.overlayColor,
  this.splashRadius,
  this.focusNode,
  this.onFocusChange,
  this.autofocus = false,
  this.tileColor,
  this.title,
  this.subtitle,
  this.isThreeLine = false,
  this.dense,
  this.contentPadding,
  this.secondary,
  this.selected = false,
  this.controlAffinity = ListTileControlAffinity.platform,
  this.shape,
  this.selectedTileColor,
  this.visualDensity,
  this.enableFeedback,
  this.hoverColor,
}) : _switchListTileType = _SwitchListTileType.material,
     applyCupertinoTheme = false,
     assert(activeThumbImage != null || onActiveThumbImageError == null),
     assert(inactiveThumbImage != null || onInactiveThumbImageError == null),
     assert(!isThreeLine || subtitle != null);