Checkbox constructor
const
Checkbox({
- Key? key,
- double padding = 8,
- required CheckboxState state,
- required ValueChanged<
CheckboxState> ? onChanged, - Widget? leading,
- Widget? trailing,
- bool tristate = false,
- bool? enabled,
- double? size,
- double? gap,
- Color? activeColor,
- Color? borderColor,
- 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 displayonChanged
(ValueChangedleading
(Widget?, optional): widget displayed before checkboxtrailing
(Widget?, optional): widget displayed after checkboxtristate
(bool, default: false): enable indeterminate state cyclingenabled
(bool?, optional): override interactivity (null = auto-detect)size
(double?, optional): override checkbox square sizegap
(double?, optional): override spacing around checkboxactiveColor
(Color?, optional): override checked state colorborderColor
(Color?, optional): override border colorborderRadius
(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,
});