fixed overwrite on internal copy, DST drift in widget anchors, inline errors without controller and removed dead room lookup
This commit is contained in:
@@ -13,6 +13,9 @@ class ConfirmDialog extends StatelessWidget {
|
||||
/// Label of the cancel button. Set to `null` for a single-button dialog
|
||||
/// (only the confirm action is rendered).
|
||||
final String? cancelButton;
|
||||
|
||||
/// Optional: without [onConfirm]/[onConfirmAsync] the dialog only reports
|
||||
/// the decision via [ask].
|
||||
final void Function()? onConfirm;
|
||||
final AsyncActionCallback? onConfirmAsync;
|
||||
final AsyncErrorBuilder? errorBuilder;
|
||||
@@ -27,15 +30,17 @@ class ConfirmDialog extends StatelessWidget {
|
||||
this.onConfirm,
|
||||
this.onConfirmAsync,
|
||||
this.errorBuilder,
|
||||
}) : assert(
|
||||
onConfirm != null || onConfirmAsync != null,
|
||||
'ConfirmDialog requires either onConfirm or onConfirmAsync',
|
||||
);
|
||||
});
|
||||
|
||||
void asDialog(BuildContext context) {
|
||||
showDialog(context: context, builder: build);
|
||||
}
|
||||
|
||||
/// Resolves to true once confirmed – with [onConfirmAsync] only after it
|
||||
/// succeeded.
|
||||
Future<bool> ask(BuildContext context) async =>
|
||||
await showDialog<bool>(context: context, builder: build) ?? false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AlertDialog(
|
||||
icon: icon != null ? Icon(icon) : null,
|
||||
@@ -59,8 +64,8 @@ class ConfirmDialog extends StatelessWidget {
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Haptics.confirm();
|
||||
Navigator.of(context).pop();
|
||||
onConfirm!();
|
||||
Navigator.of(context).pop(true);
|
||||
onConfirm?.call();
|
||||
},
|
||||
child: Text(confirmButton),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user