Checkbox class

An interactive checkbox widget for toggling boolean flags.

Interfaces

  • Keyboard: When focused is true, pressing Space (' '), Enter ('\n'), or Carriage Return ('\r') toggles value and triggers onChanged.
  • Mouse: Left-clicking inside bounds toggles value and triggers onChanged.

Example Usage

Checkbox(
  value: isAgreed,
  label: 'I agree to the terms',
  onChanged: (val) {
    setState(() => isAgreed = val);
  },
);

Properties and Styling

Property Type Description
value bool Current check state (checked if true).
label String Descriptive text label next to the checkbox.
onChanged Function(bool) Callback triggered when state toggles.
focused bool Whether the widget has keyboard focus.
style Style Normal rendering style.
focusedStyle Style Style applied when focused is true.
Inheritance
Implemented types

Constructors

Checkbox({required bool value, required String label, required void onChanged(bool newValue), bool focused = false, Style style = Style.empty, Style focusedStyle = const Style(modifiers: Modifier.reverse)})
Creates a new Checkbox.
const

Properties

focused bool
Whether the widget has keyboard focus.
final
focusedStyle Style
The rendering style applied when the checkbox is focused.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
The optional key for this widget.
finalinherited
label String
The descriptive text label next to the checkbox.
final
onChanged → void Function(bool newValue)
The callback triggered when the state toggles.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
style Style
The normal rendering style.
final
value bool
The current check state (checked if true).
final

Methods

createElement() Element
Creates an Element to manage this widget's location in the tree.
inherited
getIntrinsicHeight(int width) int
Computes the intrinsic height of this widget under the given width constraint.
inherited
handleKeyEvent(KeyEvent event) bool
Handles key activations (Space or Enter).
override
handleMouseEvent(MouseEvent event, int localX, int localY) → void
Handles mouse clicks.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
render(Buffer buffer, Rect area) → void
Renders the widget onto the provided buffer within the specified area.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited