Buttons trigger actions when pressed.
Primary button with Material or Cupertino styling.
button := material.NewButton(
&widgets.Text{Data: "Click Me"},
func() {
fmt.Println("Button clicked!")
},
)button := cupertino.NewButton(
&widgets.Text{Data: "Click Me"},
func() {
fmt.Println("Button clicked!")
},
)button := adaptive.NewButton("Click Me", func() {
fmt.Println("Button clicked!")
})Material:
ButtonStyleFilled- Filled with solid color (default)ButtonStyleOutlined- Outlined with borderButtonStyleText- Text only, no background
// Filled button
filledBtn := material.NewButton(child, onPressed)
filledBtn.Style = material.ButtonStyleFilled
// Outlined button
outlinedBtn := material.NewOutlinedButton("Outlined", onPressed)
// Text button
textBtn := material.NewTextButton("Text", onPressed)Cupertino:
ButtonTypeFilled- Filled with color (default)ButtonTypeGray- Gray backgroundButtonTypePlain- Text only
// Filled button
filledBtn := cupertino.NewButton(child, onPressed)
// Gray button
grayBtn := cupertino.NewGrayButton("Gray", onPressed)
// Text button
textBtn := cupertino.NewTextButton("Text", onPressed)Material:
OnPressed- Callback when pressedChild- Button contentStyle- Button styleBackgroundColor- Custom background colorForegroundColor- Text/icon colorDisabledColor- Color when disabledElevation- Shadow elevationBorderRadius- Corner radiusPadding- Internal paddingMinWidth/MinHeight- Minimum sizeEnabled- Whether button is enabled
Cupertino:
OnPressed- Callback when pressedChild- Button contentType- Button typeColor- Custom colorDisabledColor- Color when disabledBorderRadius- Corner radius (default 8.0)Padding- Internal paddingMinSize- Minimum size (default 44.0)Enabled- Whether button is enabled
button := material.NewButton(
&widgets.Text{Data: "Custom Button"},
onPressed,
)
button.BackgroundColor = goflow.NewColor(76, 175, 80, 255) // Green
button.ForegroundColor = goflow.NewColor(255, 255, 255, 255) // White
button.Elevation = 4.0
button.BorderRadius = 8.0canSubmit := signals.New(false)
button := material.NewButton(
&widgets.Text{Data: "Submit"},
func() {
if !canSubmit.Get() {
return
}
submit()
},
)
button.Enabled = canSubmit.Get()Text-only button (Material).
button := material.NewTextButton("Cancel", func() {
fmt.Println("Cancelled")
})Equivalent to:
button := material.NewButton(&widgets.Text{Data: "Cancel"}, onPressed)
button.Style = material.ButtonStyleText- Secondary actions
- Navigation links
- Dialog actions
- Less prominent actions
&widgets.Row{
Children: []goflow.Widget{
material.NewTextButton("Cancel", onCancel),
material.NewTextButton("OK", onOK),
},
MainAxisAlignment: widgets.MainAxisEnd,
}Outlined button with border (Material).
button := material.NewOutlinedButton("Learn More", func() {
openLearnMore()
})- Medium emphasis actions
- Alternative to filled buttons
- Actions that need visibility but not dominance
&widgets.Row{
Children: []goflow.Widget{
material.NewButton(&widgets.Text{Data: "Primary"}, onPrimary),
material.NewOutlinedButton("Secondary", onSecondary),
material.NewTextButton("Tertiary", onTertiary),
},
MainAxisAlignment: widgets.MainAxisSpaceEvenly,
}Button with icon.
button := widgets.NewIconButton(
widgets.IconFavorite,
func() {
toggleFavorite()
},
)
button.Color = goflow.NewColor(244, 67, 54, 255) // Red
button.IconSize = 28.0Icon- Icon to displayOnPressed- Callback when pressedIconSize- Size of icon (default 24.0)Color- Icon colorTooltip- Tooltip textPadding- Padding around icon
appBar := material.NewAppBar(&widgets.Text{Data: "Title"})
appBar.Actions = []goflow.Widget{
widgets.NewIconButton(widgets.IconSearch, onSearch),
widgets.NewIconButton(widgets.IconSettings, onSettings),
}isLiked := signals.New(false)
likeButton := widgets.NewIconButton(
func() widgets.IconData {
if isLiked.Get() {
return widgets.IconFavorite
}
return widgets.IconFavoriteBorder
}(),
func() {
isLiked.Set(!isLiked.Get())
},
)
likeButton.Color = func() *goflow.Color {
if isLiked.Get() {
return goflow.NewColor(244, 67, 54, 255) // Red
}
return nil
}()Material Design FAB for primary actions.
fab := material.NewFloatingActionButton(
widgets.NewIcon(widgets.IconAdd),
func() {
createNew()
},
)OnPressed- Callback when pressedChild- FAB content (usually icon)BackgroundColor- Background colorForegroundColor- Icon colorElevation- Shadow elevation (default 6.0)Mini- Use smaller sizeTooltip- Tooltip text
fab := material.NewFloatingActionButton(
widgets.NewIcon(widgets.IconEdit),
onEdit,
)
fab.Mini = true
fab.Elevation = 4.0fab := material.NewFloatingActionButton(
widgets.NewIcon(widgets.IconSend),
sendMessage,
)
fab.BackgroundColor = goflow.NewColor(33, 150, 243, 255) // Blue
fab.ForegroundColor = goflow.NewColor(255, 255, 255, 255) // White&material.Scaffold{
AppBar: appBar,
Body: body,
FloatingActionButton: material.NewFloatingActionButton(
widgets.NewIcon(widgets.IconAdd),
onAdd,
),
}// Primary action - filled button
material.NewButton(&widgets.Text{Data: "Save"}, onSave)
// Secondary action - outlined button
material.NewOutlinedButton("Preview", onPreview)
// Tertiary action - text button
material.NewTextButton("Cancel", onCancel)isLoading := signals.New(false)
button := material.NewButton(
func() goflow.Widget {
if isLoading.Get() {
return &widgets.Row{
Children: []goflow.Widget{
&widgets.ProgressIndicator{},
&widgets.Text{Data: "Loading..."},
},
}
}
return &widgets.Text{Data: "Submit"}
}(),
func() {
isLoading.Set(true)
// ... async operation
isLoading.Set(false)
},
)
button.Enabled = !isLoading.Get()&widgets.Row{
Children: []goflow.Widget{
widgets.NewIcon(widgets.IconSave),
&widgets.Text{Data: "Save"},
},
}// Material minimum: 88x36 (default)
// Cupertino minimum: 44x44 (default)
button := material.NewButton(child, onPressed)
// Already has appropriate minimum size
// For custom buttons, ensure minimum size
customButton := &widgets.Container{
MinWidth: 88.0,
MinHeight: 36.0,
Child: buttonContent,
}&widgets.Row{
Children: []goflow.Widget{
material.NewOutlinedButton("Back", onBack),
widgets.NewSpacer(),
material.NewButton(&widgets.Text{Data: "Next"}, onNext),
},
}formValid := signals.NewComputed(func() bool {
return name.Get() != "" && email.Get() != ""
})
submitButton := material.NewButton(
&widgets.Text{Data: "Submit"},
onSubmit,
)
submitButton.Enabled = formValid.Get()// Define button styles
var (
primaryButtonColor = goflow.NewColor(33, 150, 243, 255)
secondaryButtonColor = goflow.NewColor(156, 39, 176, 255)
)
func createPrimaryButton(text string, onPressed func()) goflow.Widget {
btn := material.NewButton(&widgets.Text{Data: text}, onPressed)
btn.BackgroundColor = primaryButtonColor
return btn
}