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.



Minimal
Section titled “Minimal”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
Section titled “Variants”Variants: primary, secondary, quiet, destructive.
Primary
Section titled “Primary”The one main action on a screen: pay, continue, confirm. Filled with accent. Use one primary per screen.
PaymentButton(label: 'Continue', onPressed: next);Secondary
Section titled “Secondary”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,);Destructive
Section titled “Destructive”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); },);One primary per surface
Section titled “One primary per surface”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.
No warning button
Section titled “No warning button”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,);Disabled
Section titled “Disabled”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.
With an icon
Section titled “With an icon”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.
Sizes and widths
Section titled “Sizes and widths”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.
Width (D59, D59a, D62)
Section titled “Width (D59, D59a, D62)”| 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.
Which variant when
Section titled “Which variant when”| 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 |
Customization
Section titled “Customization”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.
- Product default: configure
PaymentThemeandPaymentButtonThemeonce in the app theme. Everyday buttons then pass onlyvariant,sizeandwidth, neverstyle. - Feature theme: a scoped family theme when every button in one subtree needs a different look.
- 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.
- One-off override: an inline
stylefor 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).
Product default
Section titled “Product default”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,);Feature theme
Section titled “Feature theme”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,);Reusable host preset
Section titled “Reusable host preset”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 screenPaymentButton( label: 'Add card', variant: PaymentButtonVariant.quiet, size: PaymentSize.small, style: cardRowAction(context), onPressed: addCard,);
// Payouts screenPaymentButton( label: 'Add bank account', variant: PaymentButtonVariant.quiet, size: PaymentSize.small, style: cardRowAction(context), onPressed: addBankAccount,);One-off override
Section titled “One-off override”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,);Supported properties and states
Section titled “Supported properties and states”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.


States
Section titled “States”A null onPressed disables the button. While a returned Future runs, the button shows its busy state and blocks repeated activation.
Do and don’t
Section titled “Do and don’t”Do: One primary per view; supporting receipt/report actions are secondary; Cancel is quiet.
Don’t: Put two primary buttons in one product view.
Content guidelines
Section titled “Content guidelines”- 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”.
Accessibility
Section titled “Accessibility”- 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.
In the example app
Section titled “In the example app”

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.
| Parameter | Type | Default | Description |
|---|---|---|---|
focusNode: | FocusNode? | — | Host focus node, for example for menu focus return. |
label:required | String | — | Specific outcome of pressing the button. Wraps rather than truncates. |
onPressed:required | FutureOr<void> Function()? | — | Called once per action; null disables the button. Futures lock repeat presses. |
variant: | PaymentButtonVariant | PaymentButtonVariant.primary | Visual priority: one primary action per view. |
size: | PaymentSize | PaymentSize.medium | Drawn height: small 36, medium 48, large 56 dp. Hit box stays at least 48. |
width: | PaymentWidth | PaymentWidth.fill | Fill 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: | bool | false | Initial route focus, useful for the safe choice in destructive dialogs. |
busy: | bool | false | Externally 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
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 |
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.
| Parameter | Type | Default | Description |
|---|---|---|---|
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.
| Value | Description |
|---|---|
primary | The one main action: filled with the accent. |
secondary | An alternative to the main action: outlined. |
quiet | A low-emphasis action such as "Cancel" or "Not now": text only. |
destructive | An 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.
| Value | Description |
|---|---|
small | Module headers, table or chip rows; never the main action. |
medium | Default, today's visual size. |
large | One primary action on a full-screen wide view. |
PaymentWidth
enum PaymentWidth · lib/src/foundation/payment_tokens.dart
Width policy; labels wrap and never truncate.
| Value | Description |
|---|---|
fill | Parent width, the default. |
hug | Content width. |
See also
Section titled “See also”- Dialog to confirm before a destructive action.
- Action tile for rows that open something.
- Payment attempt and status for the payment flow around the pay button.