Skip to content
Get started
Menu
Get started

Button

PaymentButton starts an action. When onPressed returns a Future, the button shows a busy state and ignores more taps until it completes, so a double tap sends one callback.

Primary, secondary, quiet and destructive buttons in default, disabled, busy and focused states, with three sizes.Primary, secondary, quiet and destructive buttons in default, disabled, busy and focused states, with three sizes.
Button
Primary, secondary, quiet and destructive buttons in default, disabled, busy and focused states, with three sizes at 200 percent text.
200% text

Add the published package, then paste this complete example into lib/main.dart.

import 'package:flutter/material.dart';
import 'package:rakit_ui/rakit_ui.dart';
void main() => runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Example')),
body: Builder(builder: (context) => Padding(
padding: const EdgeInsets.all(16),
child: PaymentButton(
label: 'Show message',
onPressed: () => ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Action received')),
),
),
)),
),
));

Variants: primary, secondary, quiet, destructive.

The one main action on a screen: pay, continue, confirm. Filled with accent. Use one primary per screen.

PaymentButton(label: 'Continue', onPressed: next);

An alternative to the main action, such as “Change method”. Outlined with the 3:1 border color.

PaymentButton(
label: 'Change method',
variant: PaymentButtonVariant.secondary,
onPressed: openMethods,
);

A low-emphasis action such as “Not now” or “Cancel”: text only.

A quiet button that hugs its label is a text action, like a link: its text starts on the column edge, and its box (the press and focus state) hangs outward by its padding, at most 12 dp, into the gutter. Inside a row’s trailing slot the text sits on the end edge instead. In a button group, and when it fills the width (footers, confirm sheets), its label stays centred (#65). Put quiet buttons that sit side by side in a PaymentButtonGroup rather than your own Row.

PaymentButton(
label: 'Not now',
variant: PaymentButtonVariant.quiet,
onPressed: dismiss,
);

An action that cannot be undone, such as removing a saved card. Filled in the danger tone with the surface color for the label, the same colors as the confirm button of a destructive dialog. The label must say what happens, so color is never the only signal. Ask first with showPaymentConfirmDialog where the action matters, and never use it for the pay button.

PaymentButton(
label: 'Remove card',
icon: Icons.delete_outline,
variant: PaymentButtonVariant.destructive,
onPressed: () async {
final ok = await showPaymentConfirmDialog(
context,
title: 'Remove this card?',
message: 'You can add it again later.',
confirmLabel: 'Remove card',
destructive: true,
);
if (ok) await host.removeCard(card.id);
},
);

A screen, sheet or dialog has at most one primary button: its completion action. A button that only opens another surface, such as “Open sheet”, is secondary, and the sheet’s own “Done” is primary. Use equal-weight secondaries only for peer alternatives with no default, such as Share and Download.

There is no warning variant. A warning is a state, so show it with a banner, a badge or a toast next to the action. The button’s label says what happens.

A button is busy while the Future from onPressed runs, or while you pass busy: true for an action you run elsewhere, such as a submit your coordinator owns. The label keeps its space so the layout does not jump, a spinner takes its place, and screen readers hear busyLabel (default “Working…”). Under reduced motion the spinner is a still hourglass.

PaymentButton(
label: 'Pay Rp102.500',
busy: coordinator.submitting,
busyLabel: 'Sending payment',
onPressed: coordinator.submit,
);

Pass onPressed: null. Every variant uses the disabled label color; the filled and outlined variants also turn surfaceMuted. Tell people why nearby, for example with a caption under the button, because a disabled button cannot explain itself.

icon puts a 16 px icon in small buttons and a 20 px icon in medium and large buttons before the label. In medium and large buttons it grows with the text up to 32 px at 200%. When the label wraps at large text, the icon sits beside its first line and the two stay centred together. Use it when the icon adds meaning (delete, download), not as decoration on every button.

Variants: primary, secondary, quiet, destructive.

Size Visual height Horizontal padding at 100% Icon / busy spinner
small 36 dp 12 dp 16 dp
medium (default) 48 dp Material default: 24 dp; quiet 12 dp 20 dp
large 56 dp 24 dp 20 dp

Every size occupies a hit box of at least 48 × 48 dp. The small visual is centered inside it; the keyboard ring follows the visual. Use small for a module-header action such as Add card. Keep the main Pay action medium or large. Material density is pinned to standard, so medium buttons draw at 48 dp. Product targets are iOS and Android phones and tablets.

width: PaymentWidth.fill fills the parent by default. PaymentWidth.hug sizes to the label with a 112 dp minimum; a quiet hug button outside a button group hugs its label with only the 48 dp floor, so its text can start on the column edge. Put hug buttons inside an Align or Wrap; a stretching parent overrides hug. Long labels wrap and never truncate.

autofocus focuses the action when its route opens. Focus Cancel in a destructive confirmation; focus Confirm for an ordinary confirmation.

The documentation specimen intentionally shows multiple primary states together. Product views keep one primary action.

focusNode supports host focus return, including custom menu triggers.

Button group now composes related status and dialog actions. Overflow menus wrap long labels at large text.

Where the button sits On phones Wide
Footer of a view or page, sheet, confirm dialog: the action that finishes or advances the task Full width, primary on top, at most one quiet action under it Hug, at the end edge
Page header Not a button: one action is a title-row link “Label ›”, more go behind ⋮ Hug
Rows, cards, banners, state messages, tables Hug Hug

The screen’s priority action pins at the bottom; a full-width button in a header would read as the main step and push the content down.

Situation Variant / composition Payment example
Continue KYC primary One primary per view; supporting receipt/report actions are secondary; Cancel is quiet.

Use Link for inline destinations.

Use the first row that matches:

The button is… Variant
The single next action primary
Not the next action, and its consequence cannot be undone destructive, behind a confirmation
A supporting action that must stay visible secondary
Any other supporting action quiet

PaymentButtonStyle changes enabled appearance. PaymentButtonTheme is a Flutter theme extension for button-family defaults, independent of input and sheet styling.

Adopt customization in this order. Most buttons need only the first step.

  1. Product default: configure PaymentTheme and PaymentButtonTheme once in the app theme. Everyday buttons then pass only variant, size and width, never style.
  2. Feature theme: a scoped family theme when every button in one subtree needs a different look.
  3. Host preset: a named host function for a subset repeated across screens, where a scoped theme would also change buttons that should keep the default. Presets are host code, not kit API.
  4. One-off override: an inline style for one exceptional instance, changing only the fields that differ.

Repeating the same inline style across screens is never the default: copies drift apart and skip theme changes. Brand looks belong in the theme, not in new variants (§9).

Build the theme per color scheme, so light and dark each resolve their own tokens:

ThemeData paymentAppTheme(ColorScheme scheme) {
final payment = PaymentTheme.fromColorScheme(scheme);
return ThemeData(
colorScheme: scheme,
extensions: [
payment,
PaymentButtonTheme(
style: PaymentButtonStyle(
// Buttons follow the box radius instead of the input radius.
borderRadius: payment.borderRadius,
textStyle: const TextStyle(fontWeight: FontWeight.w700),
),
),
],
);
}
// MaterialApp(theme: paymentAppTheme(lightScheme),
// darkTheme: paymentAppTheme(darkScheme), ...)

Call sites stay semantic and omit style:

PaymentButton(label: 'Pay now', onPressed: pay);
PaymentButton(
label: 'View receipt',
variant: PaymentButtonVariant.secondary,
onPressed: openReceipt,
);

Scope a family theme without replacing unrelated extensions. copyWith replaces a whole variant entry, so merge into the parent’s entry to keep its fields:

// Inside the feature's build method.
final parent = Theme.of(context);
final payment = PaymentTheme.of(context);
final buttons = parent.extension<PaymentButtonTheme>() ??
const PaymentButtonTheme();
final accentOutline = PaymentButtonStyle(
borderColor: payment.accent,
foregroundColor: payment.accent,
);
return Theme(
data: parent.copyWith(extensions: [
...parent.extensions.values,
buttons.copyWith(
secondary: buttons.secondary?.merge(accentOutline) ?? accentOutline,
),
]),
child: rewardsView,
);

Use a named preset when the same subset repeats on several screens and other buttons of that variant keep the default. Take BuildContext and read PaymentTheme.of(context), so the preset follows light/dark and brand changes. Don’t keep resolved colors in a top-level final; that freezes one theme.

// Host code: a compact tonal action for card rows.
PaymentButtonStyle cardRowAction(BuildContext context) {
final payment = PaymentTheme.of(context);
return PaymentButtonStyle(
backgroundColor: payment.surfaceMuted,
foregroundColor: payment.textPrimary,
);
}
// Saved cards screen
PaymentButton(
label: 'Add card',
variant: PaymentButtonVariant.quiet,
size: PaymentSize.small,
style: cardRowAction(context),
onPressed: addCard,
);
// Payouts screen
PaymentButton(
label: 'Add bank account',
variant: PaymentButtonVariant.quiet,
size: PaymentSize.small,
style: cardRowAction(context),
onPressed: addBankAccount,
);

An instance overrides only the fields it provides; everything else keeps the theme. Here one button beside a promo-code field keeps the input radius to line up with it:

PaymentButton(
label: 'Apply',
variant: PaymentButtonVariant.secondary,
style: PaymentButtonStyle(
borderRadius: PaymentTheme.of(context).controlBorderRadius,
),
onPressed: applyCode,
);
// Incorrect: one appearance pasted inline on every screen.
// Move it to the app theme, a feature theme or a named preset.
PaymentButton(
label: 'Pay now',
style: PaymentButtonStyle(
backgroundColor: const Color(0xFF0B5FFF),
foregroundColor: Colors.white,
borderRadius: BorderRadius.circular(24),
),
onPressed: pay,
);

Resolution: semantic defaults for variant/size → theme style → theme variant entry → instance style. A null field retains the preceding value. Nested themes replace the extension; derive from the parent with copyWith to preserve its button settings.

Kit slots that lay a button out at hug width (button group, banner actions, view and page module footers, action bar) keep its instance style. A button group that collapses into a menu shows menu rows instead, which use menu styling.

During theme transitions, concrete override pairs interpolate. An override present at only one endpoint switches at the midpoint: null still means inherit, rather than a transparent color or zero radius. Ignored text paint and inheritance fields are removed before interpolation.

Property Effect
backgroundColor Enabled fill, including secondary/quiet when supplied.
foregroundColor Enabled label, icon, busy indicator and derived pressed/hover state layers.
borderColor Enabled secondary outline; ignored by other variants.
borderRadius Button shape and matching keyboard focus ring.
textStyle Typography merged over the heading role. Color, paint, background, shadows, decoration and inherit are ignored.

Size, padding, hit target, density, alignment, icon size, elevation, focus color, state-specific colors and animation are kit-owned. Use size and width for supported geometry. There is no unrestricted Flutter ButtonStyle pass-through or custom-content builder.

Disabled buttons use kit disabled / surfaceMuted tokens, ignoring custom enabled colors. Quiet buttons with no custom fill remain unfilled; a custom quiet fill becomes surfaceMuted when disabled. Busy buttons retain the label’s layout and use the current state’s foreground for the spinner, including disabled+busy. Keyboard focus stays neutral and follows the custom radius. Reduced motion and repeat-press protection are unchanged.

The host verifies custom foreground/background pairs and outlines in light/dark and all relevant interaction states. Keep text size and line height positive and check long labels at 200% text. Repeated overrides belong in the app or feature theme, or a named host preset, rather than inline at every call site.

Scoped pill button theme with custom colors, secondary, disabled and busy states, and a rectangular instance override.Scoped pill button theme with custom colors, secondary, disabled and busy states, and a rectangular instance override.
Button-family theme and instance style

A null onPressed disables the button. While a returned Future runs, the button shows its busy state and blocks repeated activation.

Do: One primary per view; supporting receipt/report actions are secondary; Cancel is quiet.

Don’t: Put two primary buttons in one product view.

  • Start with a verb and say what happens: “Pay Rp102.500”, “Remove card”, “Check status”. Avoid “OK” and “Submit”.
  • Put the amount in the pay button, formatted with MoneyFormat, so the button and the summary agree.
  • Use sentence case and no end punctuation.
  • Keep labels short enough for one line at normal text size. At large text they wrap rather than truncate.
  • A destructive label names the thing it destroys: “Remove card”, not “Remove”.
  • 48 dp minimum height. Keyboard focus draws the kit’s focus ring, never the brand color.
  • Full-width buttons do not scale on press; Material’s pressed layer is the feedback.
  • While busy, the button is a live region that announces busyLabel.
Example sign in screen with synthetic dataExample sign in screen with synthetic data
Example: sign in

PaymentButton

class PaymentButton extends StatefulWidget · lib/src/foundation/primitives.dart

Button with consistent idle/busy/disabled feedback.

When onPressed returns a Future the button locks itself until it completes, so only one callback is active at a time. This is interaction protection; hosts still deduplicate on the server.

ParameterTypeDefaultDescription
focusNode:FocusNode?—Host focus node, for example for menu focus return.
label:requiredString—Specific outcome of pressing the button. Wraps rather than truncates.
onPressed:requiredFutureOr<void> Function()?—Called once per action; null disables the button. Futures lock repeat presses.
variant:PaymentButtonVariantPaymentButtonVariant.primaryVisual priority: one primary action per view.
size:PaymentSizePaymentSize.mediumDrawn height: small 36, medium 48, large 56 dp. Hit box stays at least 48.
width:PaymentWidthPaymentWidth.fillFill the parent or hug the wrapped label, at least 112 dp wide. A quiet button that hugs, outside a PaymentButtonGroup, keeps only the 48 dp floor and starts its text on the column edge.
autofocus:boolfalseInitial route focus, useful for the safe choice in destructive dialogs.
busy:boolfalseExternally owned busy state, e.g. a submit the coordinator is running.
busyLabel:String?—Spoken status while busy, defaulting to the localized working label.
icon:IconData?—Optional leading icon in the label color.
style:PaymentButtonStyle?—Appearance after token and button-family defaults; see PaymentButtonStyle. Disabled colors, focus, sizing and motion remain kit-owned.

PaymentButtonStyle

class PaymentButtonStyle · lib/src/foundation/button_style.dart

Partial button appearance, resolved after semantic and family defaults.

Disabled colors, focus color, padding, sizing, state layers and motion stay kit-owned. Hosts verify contrast for custom enabled color pairs in light and dark. This type deliberately does not forward unrestricted ButtonStyle.

ParameterTypeDefaultDescription
backgroundColor:Color?—Enabled fill; secondary and quiet variants have no fill by default.
foregroundColor:Color?—Enabled label, icon and spinner color, also used for pressed/hover layers.
borderColor:Color?—Enabled secondary outline; ignored by the other variants.
borderRadius:BorderRadius?—Button corners; the keyboard focus ring follows the same radii.
textStyle:TextStyle?—Typography merged over the heading role, keeping unspecified fields.

Color, paint, background, shadows, decorations and inherit are ignored; use foregroundColor. Font size and height must be positive when supplied.

PaymentButtonTheme

class PaymentButtonTheme extends ThemeExtension<PaymentButtonTheme> · lib/src/foundation/button_style.dart

Button-family overrides registered in ThemeData.extensions.

Resolution is token defaults, shared style, variant style, then instance. A scoped Theme may change buttons without changing input or sheet corners. Preserve unrelated parent extensions. Nested themes replace this extension; derive them with copyWith when parent values should remain.

ParameterTypeDefaultDescription
style:PaymentButtonStyle?—Shared appearance applied before variant overrides.
primary:PaymentButtonStyle?—Primary appearance.
secondary:PaymentButtonStyle?—Secondary appearance.
quiet:PaymentButtonStyle?—Quiet appearance.
destructive:PaymentButtonStyle?—Destructive appearance.

PaymentButtonVariant

enum PaymentButtonVariant · lib/src/foundation/primitives.dart

How much weight a PaymentButton carries. Use one primary per screen.

ValueDescription
primaryThe one main action: filled with the accent.
secondaryAn alternative to the main action: outlined.
quietA low-emphasis action such as "Cancel" or "Not now": text only.
destructiveAn action that cannot be undone, such as removing a saved card: filled in the danger tone. The label must say what happens, so color is never the only signal. Usually the confirm step after a showPaymentConfirmDialog, never the pay button.

PaymentSize

enum PaymentSize · lib/src/foundation/payment_tokens.dart

Visual size only; layout box and hit area stay at least 48×48 dp. Components document their heights.

ValueDescription
smallModule headers, table or chip rows; never the main action.
mediumDefault, today's visual size.
largeOne primary action on a full-screen wide view.

PaymentWidth

enum PaymentWidth · lib/src/foundation/payment_tokens.dart

Width policy; labels wrap and never truncate.

ValueDescription
fillParent width, the default.
hugContent width.