33 lines
778 B
Dart
33 lines
778 B
Dart
/// Confirm a destructive action before it runs.
|
|
library;
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
Future<bool> confirmAction(
|
|
BuildContext context, {
|
|
required String title,
|
|
required String message,
|
|
String confirmLabel = 'Delete',
|
|
}) async {
|
|
final result = await showDialog<bool>(
|
|
context: context,
|
|
builder: (context) {
|
|
return AlertDialog(
|
|
title: Text(title),
|
|
content: Text(message),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(false),
|
|
child: const Text('Cancel'),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(true),
|
|
child: Text(confirmLabel),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
return result == true;
|
|
}
|