Button
A tappable button with optional haptic feedback.
Basic Usage
// Themed (recommended)
theme.ButtonOf(ctx, "Submit", handleSubmit)
// Explicit
widgets.Button{
Label: "Submit",
OnTap: handleSubmit,
Color: colors.Primary,
TextColor: colors.OnPrimary,
Padding: layout.EdgeInsetsSymmetric(24, 14),
BorderRadius: 8,
}
Properties
| Property | Type | Description |
|---|---|---|
Label | string | Button text |
OnTap | func() | Tap callback |
Color | graphics.Color | Background color |
Gradient | *graphics.Gradient | Optional background gradient (replaces Color) |
TextColor | graphics.Color | Label color |
FontSize | float64 | Label font size in logical pixels |
Padding | layout.EdgeInsets | Inner padding |
BorderRadius | float64 | Corner radius |
Haptic | bool | Enable haptic feedback on tap |
Disabled | bool | Disable the button |
DisabledColor | graphics.Color | Background color when disabled |
DisabledTextColor | graphics.Color | Text color when disabled |
Themed vs Explicit
// Themed: reads colors, padding, font size, border radius from ButtonThemeData
button := theme.ButtonOf(ctx, "Submit", handleSubmit)
// Override specific theme values with builder methods
button := theme.ButtonOf(ctx, "Submit", onSubmit).
WithBorderRadius(0).
WithPadding(layout.EdgeInsetsSymmetric(32, 16))
Common Patterns
Destructive Action
widgets.Button{
Label: "Delete",
OnTap: handleDelete,
Color: colors.Error,
TextColor: colors.OnError,
BorderRadius: 8,
Haptic: true,
}
Button Row
widgets.Row{
MainAxisAlignment: widgets.MainAxisAlignmentSpaceEvenly,
CrossAxisAlignment: widgets.CrossAxisAlignmentCenter,
Children: []core.Widget{
theme.ButtonOf(ctx, "Cancel", handleCancel),
theme.ButtonOf(ctx, "Save", handleSave),
},
}
Related
- TextField for text input
- Forms & Validation for form submission