loading state and error handling refactor
This commit is contained in:
@@ -1,14 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'async_action_button.dart';
|
||||
|
||||
class ConfirmDialog extends StatelessWidget {
|
||||
final String title;
|
||||
final String content;
|
||||
final IconData? icon;
|
||||
final String confirmButton;
|
||||
final String cancelButton;
|
||||
final void Function() onConfirm;
|
||||
const ConfirmDialog({super.key, required this.title, this.content = '', this.icon, this.confirmButton = 'Ok', this.cancelButton = 'Abbrechen', required this.onConfirm});
|
||||
final void Function()? onConfirm;
|
||||
final AsyncActionCallback? onConfirmAsync;
|
||||
final AsyncErrorBuilder? errorBuilder;
|
||||
|
||||
const ConfirmDialog({
|
||||
super.key,
|
||||
required this.title,
|
||||
this.content = '',
|
||||
this.icon,
|
||||
this.confirmButton = 'Ok',
|
||||
this.cancelButton = 'Abbrechen',
|
||||
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);
|
||||
@@ -16,20 +32,33 @@ class ConfirmDialog extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AlertDialog(
|
||||
icon: icon != null ? Icon(icon) : null,
|
||||
title: Text(title),
|
||||
content: Text(content),
|
||||
actions: [
|
||||
TextButton(onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}, child: Text(cancelButton)),
|
||||
TextButton(onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
onConfirm();
|
||||
}, child: Text(confirmButton)),
|
||||
],
|
||||
);
|
||||
|
||||
icon: icon != null ? Icon(icon) : null,
|
||||
title: Text(title),
|
||||
content: Text(content),
|
||||
actions: onConfirmAsync != null
|
||||
? [
|
||||
AsyncDialogAction(
|
||||
confirmLabel: confirmButton,
|
||||
cancelLabel: cancelButton,
|
||||
onConfirm: onConfirmAsync!,
|
||||
errorBuilder: errorBuilder,
|
||||
),
|
||||
]
|
||||
: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Text(cancelButton),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
onConfirm!();
|
||||
},
|
||||
child: Text(confirmButton),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
static void openBrowser(BuildContext context, String url) {
|
||||
showDialog(
|
||||
context: context,
|
||||
|
||||
Reference in New Issue
Block a user