Skip to content
Get started
Menu
Get started

Dialog

showPaymentConfirmDialog asks a yes-or-no question before an action that cannot be undone, and returns a Future<bool>.

Run the action only after the dialog resolves to true.

On a phone the confirmation is a bottom sheet; on a wider window it is a centred dialog. The page keeps the name “Dialog”.

Remove card confirmation sheet with the destructive action above Cancel.Remove card confirmation sheet with the destructive action above Cancel.
Phone: light and dark
Remove card confirmation sheet with the destructive action above Cancel at 200 percent text.
200% text
Remove card confirmation sheet with the destructive action above Cancel, in Indonesian.
Indonesian
Remove card confirmation sheet with the destructive action above Cancel at 200 percent text, in Indonesian.
Indonesian, 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: 'Archive note',
variant: PaymentButtonVariant.secondary,
onPressed: () async {
final confirmed = await showPaymentConfirmDialog(
context,
title: 'Archive this note?',
message: 'You can restore it later.',
confirmLabel: 'Archive',
);
if (!context.mounted || !confirmed) return;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Archive confirmed')),
);
},
),
)),
),
));

Variants: ordinary confirm, destructive confirm.

The future resolves to true only when the person presses the confirm button. Cancel, tapping the scrim, Back and Escape all resolve to false.

The confirm button is filled with the accent and the cancel button is a quiet text button. The confirm button receives focus first.

destructive: true fills the confirm button in the danger tone, the same colors as a destructive button, and moves first focus to the cancel button, so Enter never confirms by accident.

The cancel button says “Cancel” by default. Pass cancelLabel when the safe choice reads better as an action of its own, such as “Keep paying”.

On a phone, when the window’s shorter side is under 600 dp, the confirmation slides up as a bottom sheet with no drag handle: the title, then the message, then the actions. The actions are stacked top-down at full width with centred labels, the confirm action on top and a quiet Cancel below. One 16 dp inset holds on every edge at every text scale, plus the bottom safe area. Language and text size never change the layout, so English, Indonesian and 200% text all look the same. At large text the title and message scroll, and the actions stay on screen. A phone held sideways (640 × 360 dp) keeps this sheet.

On a tablet, with a shorter side of 600 dp or more, the confirmation is a centred dialog, at most 400 dp wide, with the same 16 dp edges. The actions are one row of equal-width buttons with Cancel first and the confirm action trailing.

Path Phone sheet Wide dialog Result
Confirm button yes yes true
Cancel button yes yes false
Scrim tap yes yes false
Swipe down yes — false
Back yes yes false
Escape yes yes false
Enter activates the focused button activates the focused button true only when the confirm action has focus

Cancel is quiet; Confirm is primary or destructive. Keyboard focus uses the neutral ring, starting on Cancel for destructive actions and on Confirm otherwise. Enter activates that safe initial choice. Opening a confirmation from inside a sheet, such as the focus view’s discard question, stacks a sheet on the sheet. That is expected.

Situation Variant / composition Payment example
Discard report destructive confirm Name the consequence and keep Cancel quiet; focus Cancel for destruction.

Use Focus view for collecting a report.

Confirm resolves to true. Cancel, Back, Escape and scrim dismissal resolve to false; the host performs the confirmed operation.

Use showPaymentAsyncConfirmDialog when the prompt needs to stay open until a host action succeeds. It uses the same phone and tablet layouts, action order and initial focus. The async sheet disables swipe-to-dismiss so an in-flight operation cannot be dismissed by a drag; Cancel, scrim, Back and Escape work when idle.

final removed = await showPaymentAsyncConfirmDialog(
context,
title: 'Remove this statement?',
description: ValueListenableBuilder<String>(
valueListenable: confirmationMessage,
builder: (_, message, _) => Semantics(
liveRegion: true,
child: Text(message),
),
),
confirmLabel: 'Remove statement',
pendingLabel: 'Removing statement',
destructive: true,
onConfirm: removeSelectedStatement,
);

The host’s removeSelectedStatement handles expected failures and returns Future<bool>. Return true only after confirming success. Return false to keep the prompt open and update confirmationMessage with safe recovery instructions. The async prompt uses the root navigator so system Back reaches it even when opened from a nested page. If the callback needs to await another route, open that route on the root navigator too so it appears above the prompt. While pending, the kit prevents repeated confirmation and user dismissal. pendingLabel is announced to assistive technology.

Pass actionLabels if the next press may do something different. Its current value supplies the confirm and pending labels in place of the static strings. A null live pending label uses the localized working label. Keep the host-owned listenable alive until the dialog future completes. Updating it leaves the current dialog, button variant and pending locks in place.

final labels = ValueNotifier(const PaymentAsyncConfirmLabels(
confirmLabel: 'Remove statement',
pendingLabel: 'Removing statement',
));
var needsStatusCheck = false;
var closed = false;
try {
await showPaymentAsyncConfirmDialog(
context,
title: 'Remove this statement?',
description: const Text('It will no longer appear in saved records.'),
confirmLabel: 'Remove statement',
actionLabels: labels,
destructive: true,
onConfirm: () async {
if (needsStatusCheck) return checkRemovalStatus();
final removed = await removeStatement(); // null: outcome unknown
if (removed != null) return removed;
if (closed) return false;
needsStatusCheck = true;
labels.value = const PaymentAsyncConfirmLabels(
confirmLabel: 'Check status',
pendingLabel: 'Checking status',
);
return false;
},
);
} finally {
closed = true;
labels.dispose();
}

checkRemovalStatus reads the outcome for the same record and returns true only when removal is confirmed. Do not blindly repeat a write with an unknown outcome. The kit never retries, and changing the label does not change what onConfirm does. The example gallery’s Kit components section shows a lost removal response followed by a status check, with live recovery copy in the description.

Do: Name the consequence and keep Cancel quiet; focus Cancel for destruction.

Don’t: Ask for confirmation before every reversible interaction.

  • Ask the question in the title: “Remove this card?”, “Sign out of all devices?”.
  • Use the message for the consequence, and for what is not affected: “Payments already sent are not affected.”
  • Make confirmLabel repeat the action: “Sign out”, “Remove card”. Never “Yes” or “OK”.
  • Do not use a dialog to cancel a payment by itself. A cancel request goes to your host, and the payment stays pending until your host decides; see Sheet.

Initial focus is on Cancel for destructive actions and Confirm otherwise. Dismissal returns false; labels and messages remain readable at large text.

Example report problem screen with synthetic dataExample report problem screen with synthetic data
Example: report problem

showPaymentConfirmDialog

Future<bool> showPaymentConfirmDialog(…) · lib/src/interaction/interaction.dart

Asks before an action that cannot be undone. Resolves to true only when the person confirms; the scrim, swipe down, Back and Escape all resolve to false.

On phones (window shortest side under 600 dp, so also in landscape; D92) it is a bottom confirm sheet: title, message, then full-width actions stacked top-down with the confirm action on top and Cancel below (D45). On tablets it is a centred dialog with one row of equal-width buttons, confirm trailing. Both use one 16 dp inset at every text scale, so the layout never depends on label length.

For destructive actions the safe choice (cancel) receives focus first, so Enter never confirms by accident.

ParameterTypeDefaultDescription
contextrequiredpositionalBuildContext——
title:requiredString——
message:requiredString——
confirmLabel:requiredString——
cancelLabel:String?——
destructive:boolfalse—

showPaymentAsyncConfirmDialog

Future<bool> showPaymentAsyncConfirmDialog(…) · lib/src/interaction/interaction.dart

Presents confirmation with the same responsive layout and initial focus as showPaymentConfirmDialog, but keeps it open while the host runs onConfirm.

title names the action. description is host content (including any recovery message), with the kit's supporting body style by default. confirmLabel names the operation and cancelLabel overrides localized Cancel. pendingLabel is the spoken busy status; it defaults to the kit's localized working label. For destructive actions, Cancel receives focus.

Pass actionLabels to update both labels while the prompt is open. Its value takes precedence over the static labels, including a null pending label. The host owns the listenable and must keep it alive until the returned future completes. Updating labels does not invoke onConfirm, unlock the prompt, or change the action's variant.

Return true from onConfirm only when the host confirms success. Return false to leave the prompt open and make the actions available again. The host handles expected failures and decides whether another activation may retry the operation or should only check its status. The kit never retries. Unexpected exceptions are reported to Flutter and leave the prompt open.

The prompt uses the root navigator. While pending, repeat activation, Cancel, scrim, Back and Escape cannot dismiss it. The async sheet does not support swipe-to-dismiss. The returned future is true only for confirmed success and false on dismissal. A host that force-removes the route does not cancel the operation.

ParameterTypeDefaultDescription
contextrequiredpositionalBuildContext——
title:requiredString——
description:requiredWidget——
confirmLabel:requiredString——
onConfirm:requiredFuture<bool> Function()——
cancelLabel:String?——
pendingLabel:String?——
actionLabels:ValueListenable<PaymentAsyncConfirmLabels>?——
destructive:boolfalse—

PaymentAsyncConfirmLabels

class PaymentAsyncConfirmLabels · lib/src/interaction/interaction.dart

Action labels for an open showPaymentAsyncConfirmDialog.

ParameterTypeDefaultDescription
confirmLabel:requiredString—Visible and spoken name of the confirm action.
pendingLabel:String?—Spoken status while the action is running. Defaults to localized working.
  • Button for the destructive variant that usually opens this dialog.
  • Toast for feedback after the action ran.