SwitchListTile constructor Null safety

const SwitchListTile(
  1. {Key? key,
  2. required bool value,
  3. required ValueChanged<bool>? onChanged,
  4. Color? tileColor,
  5. Color? activeColor,
  6. Color? activeTrackColor,
  7. Color? inactiveThumbColor,
  8. Color? inactiveTrackColor,
  9. ImageProvider<Object>? activeThumbImage,
  10. ImageProvider<Object>? inactiveThumbImage,
  11. Widget? title,
  12. Widget? subtitle,
  13. bool isThreeLine,
  14. bool? dense,
  15. EdgeInsetsGeometry? contentPadding,
  16. Widget? secondary,
  17. bool selected,
  18. bool autofocus,
  19. ListTileControlAffinity controlAffinity,
  20. ShapeBorder? shape,
  21. Color? selectedTileColor}
)

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({
  Key? key,
  required this.value,
  required this.onChanged,
  this.tileColor,
  this.activeColor,
  this.activeTrackColor,
  this.inactiveThumbColor,
  this.inactiveTrackColor,
  this.activeThumbImage,
  this.inactiveThumbImage,
  this.title,
  this.subtitle,
  this.isThreeLine = false,
  this.dense,
  this.contentPadding,
  this.secondary,
  this.selected = false,
  this.autofocus = false,
  this.controlAffinity = ListTileControlAffinity.platform,
  this.shape,
  this.selectedTileColor,
}) : _switchListTileType = _SwitchListTileType.material,
     assert(value != null),
     assert(isThreeLine != null),
     assert(!isThreeLine || subtitle != null),
     assert(selected != null),
     assert(autofocus != null),
     super(key: key);