Checkbox constructor

const Checkbox({
  1. Key? key,
  2. double padding = 8,
  3. required CheckboxState state,
  4. required ValueChanged<CheckboxState>? onChanged,
  5. Widget? leading,
  6. Widget? trailing,
  7. bool tristate = false,
  8. bool? enabled,
  9. double? size,
  10. double? gap,
  11. Color? activeColor,
  12. Color? borderColor,
  13. BorderRadiusGeometry? borderRadius,
})

Creates a Checkbox widget.

The state and onChanged parameters work together to provide controlled component behavior - the widget displays the provided state and notifies of user interactions through the callback.

Parameters:

  • state (CheckboxState, required): current checkbox state to display
  • onChanged (ValueChanged
  • leading (Widget?, optional): widget displayed before checkbox
  • trailing (Widget?, optional): widget displayed after checkbox
  • tristate (bool, default: false): enable indeterminate state cycling
  • enabled (bool?, optional): override interactivity (null = auto-detect)
  • size (double?, optional): override checkbox square size
  • gap (double?, optional): override spacing around checkbox
  • activeColor (Color?, optional): override checked state color
  • borderColor (Color?, optional): override border color
  • borderRadius (BorderRadiusGeometry?, optional): override corner radius

Example:

Checkbox(
  state: isAccepted ? CheckboxState.checked : CheckboxState.unchecked,
  onChanged: (state) => setState(() {
    isAccepted = state == CheckboxState.checked;
  }),
  trailing: Text('I accept the terms and conditions'),
)

Implementation

const Checkbox({
  super.key,
  this.padding = 8,
  required this.state,
  required this.onChanged,
  this.leading,
  this.trailing,
  this.tristate = false,
  this.enabled,
  this.size,
  this.gap,
  this.activeColor,
  this.borderColor,
  this.borderRadius,
});