CheckboxListTile constructor Null safety

const CheckboxListTile(
  1. {Key? key,
  2. required bool? value,
  3. required ValueChanged<bool?>? onChanged,
  4. Color? activeColor,
  5. Color? checkColor,
  6. bool? enabled,
  7. Color? tileColor,
  8. Widget? title,
  9. Widget? subtitle,
  10. bool isThreeLine = false,
  11. bool? dense,
  12. Widget? secondary,
  13. bool selected = false,
  14. ListTileControlAffinity controlAffinity = ListTileControlAffinity.platform,
  15. bool autofocus = false,
  16. EdgeInsetsGeometry? contentPadding,
  17. bool tristate = false,
  18. ShapeBorder? shape,
  19. OutlinedBorder? checkboxShape,
  20. Color? selectedTileColor,
  21. BorderSide? side,
  22. VisualDensity? visualDensity,
  23. FocusNode? focusNode,
  24. bool? enableFeedback}
)

Creates a combination of a list tile and a checkbox.

The checkbox tile itself does not maintain any state. Instead, when the state of the checkbox changes, the widget calls the onChanged callback. Most widgets that use a checkbox will listen for the onChanged callback and rebuild the checkbox tile with a new value to update the visual appearance of the checkbox.

The following arguments are required:

  • value, which determines whether the checkbox is checked. The value can only be null if tristate is true.
  • onChanged, which is called when the value of the checkbox should change. It can be set to null to disable the checkbox.

The value of tristate must not be null.

Implementation

const CheckboxListTile({
  super.key,
  required this.value,
  required this.onChanged,
  this.activeColor,
  this.checkColor,
  this.enabled,
  this.tileColor,
  this.title,
  this.subtitle,
  this.isThreeLine = false,
  this.dense,
  this.secondary,
  this.selected = false,
  this.controlAffinity = ListTileControlAffinity.platform,
  this.autofocus = false,
  this.contentPadding,
  this.tristate = false,
  this.shape,
  this.checkboxShape,
  this.selectedTileColor,
  this.side,
  this.visualDensity,
  this.focusNode,
  this.enableFeedback,
}) : assert(tristate != null),
     assert(tristate || value != null),
     assert(isThreeLine != null),
     assert(!isThreeLine || subtitle != null),
     assert(selected != null),
     assert(controlAffinity != null),
     assert(autofocus != null);