Checkbox & Radio
Checkbox is a boolean toggle. Radio selects a single value from a group.
Checkbox
// Themed (recommended)
theme.CheckboxOf(ctx, isChecked, func(value bool) {
s.SetState(func() {
isChecked = value
})
})
// Explicit
widgets.Checkbox{
Value: isChecked,
ActiveColor: colors.Primary,
CheckColor: colors.OnPrimary,
OnChanged: func(value bool) {
s.SetState(func() {
isChecked = value
})
},
}
Checkbox Properties
| Property | Type | Description |
|---|---|---|
Value | bool | Current checked state |
ActiveColor | graphics.Color | Fill color when checked |
CheckColor | graphics.Color | Checkmark color |
OnChanged | func(bool) | Called when toggled |
Radio
// Themed (recommended)
theme.RadioOf(ctx, "email", selectedOption, func(value string) {
s.SetState(func() {
selectedOption = value
})
})
// Explicit
widgets.Radio[string]{
Value: "email",
GroupValue: selectedOption,
ActiveColor: colors.Primary,
OnChanged: func(value string) {
s.SetState(func() {
selectedOption = value
})
},
}
Radio Properties
| Property | Type | Description |
|---|---|---|
Value | T | The value this radio button represents |
GroupValue | T | Currently selected value in the group |
ActiveColor | graphics.Color | Fill color when selected |
OnChanged | func(T) | Called when selected |
Common Patterns
Radio Group
widgets.Column{
MainAxisSize: widgets.MainAxisSizeMin,
Children: []core.Widget{
theme.RadioOf(ctx, "email", contactMethod, setContactMethod),
theme.RadioOf(ctx, "phone", contactMethod, setContactMethod),
theme.RadioOf(ctx, "mail", contactMethod, setContactMethod),
},
}
Related
- Switch & Toggle for on/off controls
- Dropdown for selection from a list