Skip to main content

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

PropertyTypeDescription
LabelstringButton text
OnTapfunc()Tap callback
Colorgraphics.ColorBackground color
Gradient*graphics.GradientOptional background gradient (replaces Color)
TextColorgraphics.ColorLabel color
FontSizefloat64Label font size in logical pixels
Paddinglayout.EdgeInsetsInner padding
BorderRadiusfloat64Corner radius
HapticboolEnable haptic feedback on tap
DisabledboolDisable the button
DisabledColorgraphics.ColorBackground color when disabled
DisabledTextColorgraphics.ColorText 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),
},
}