56 lines
1.9 KiB
Dart
56 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../api/errors/error_mapper.dart';
|
|
import '../utils/clipboard_helper.dart';
|
|
|
|
class InfoDialog {
|
|
/// Shows a single-text dialog. When [copyable] is true (default for error
|
|
/// details surfaces), the dialog body is selectable and a "Kopieren" action
|
|
/// places it on the clipboard with a SnackBar confirmation.
|
|
static void show(
|
|
BuildContext context,
|
|
String info, {
|
|
bool copyable = false,
|
|
String? title,
|
|
}) {
|
|
showDialog<void>(
|
|
context: context,
|
|
builder: (dialogContext) {
|
|
final theme = Theme.of(dialogContext);
|
|
return AlertDialog(
|
|
title: title != null ? Text(title) : null,
|
|
content: SingleChildScrollView(
|
|
child: copyable
|
|
? SelectableText(info, style: theme.textTheme.bodyMedium)
|
|
: Text(info, style: theme.textTheme.bodyMedium),
|
|
),
|
|
contentPadding: const EdgeInsets.fromLTRB(20, 20, 20, 12),
|
|
actions: [
|
|
if (copyable)
|
|
TextButton.icon(
|
|
onPressed: () => copyToClipboard(dialogContext, info),
|
|
icon: const Icon(Icons.copy_outlined, size: 18),
|
|
label: const Text('Kopieren'),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.of(dialogContext).pop(),
|
|
child: const Text('Schließen'),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
/// Error dialog with the user-facing [message] (default: mapped from
|
|
/// [error]) plus the technical details when they add information.
|
|
static void showError(BuildContext context, Object error, {String? message}) {
|
|
final text = message ?? errorToUserMessage(error);
|
|
final details = errorToTechnicalDetails(error);
|
|
final body = details != null && details != text
|
|
? '$text\n\n$details'
|
|
: text;
|
|
show(context, body, copyable: true, title: 'Fehler');
|
|
}
|
|
}
|