Skip to content

Confirm an action

Require an affirmative result before performing a consequential action. A dismissed dialog must not count as confirmation.

This widget delegates the actual operation to its caller. It uses the dialog’s context when closing the route:

class RemoveItemAction extends StatelessWidget {
const RemoveItemAction({super.key, required this.onConfirmed});
final VoidCallback onConfirmed;
@override
Widget build(BuildContext context) => DievasOutlinedButton(
label: 'Remove item',
style: DievasOutlinedButtonStyle.destructive,
onPressed: () async {
final confirmed = await showDievasModal<bool>(
context: context,
builder: (dialogContext) => DievasModal(
title: 'Remove this item?',
body: 'You cannot undo this action.',
actions: [
DievasTextButton(
label: 'Cancel',
onPressed: () => closeDievasModal(dialogContext, false),
),
DievasFilledButton(
label: 'Remove',
style: DievasFilledButtonStyle.destructive,
onPressed: () => closeDievasModal(dialogContext, true),
),
],
),
);
if (!context.mounted) return;
if (confirmed == true) onConfirmed();
},
);
}

The context.mounted check handles the real possibility that the caller is disposed while awaiting the dialog. confirmed == true distinguishes explicit acceptance from false or null dismissal.

The callback is the boundary to your application command. Handle loading, persistence, failure, and any navigation there. Avoid claiming deletion succeeded before the operation finishes.

Confirm Cancel, the close button, Escape, and outside dismissal do not call onConfirmed. Confirm Remove calls it once. Check keyboard focus and return behaviour on each supported platform.

Review overlay options for dismissal and navigator configuration.