43 lines
1.3 KiB
Dart
43 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:url_launcher/url_launcher.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({Key? key, required this.title, this.content = "", this.icon, this.confirmButton = "Ok", this.cancelButton = "Abbrechen", required this.onConfirm}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return 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: () {
|
|
onConfirm();
|
|
Navigator.of(context).pop();
|
|
}, child: Text(confirmButton)),
|
|
],
|
|
);
|
|
}
|
|
|
|
static void openBrowser(BuildContext context, String url) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => ConfirmDialog(
|
|
title: "Link öffnen",
|
|
content: "Möchtest du den folgenden Link öffnen?\n${url}",
|
|
confirmButton: "Öffnen",
|
|
onConfirm: () => launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication),
|
|
),
|
|
);
|
|
}
|
|
}
|