2024-06-14 14:28:59 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
/// Show a simple message dialog
|
|
|
|
void showMsg(BuildContext context, String title, String content) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
title: Text(title),
|
|
|
|
content: Text(content),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
child: const Text('OK'),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-18 02:24:42 +02:00
|
|
|
/// Show an error colored SnackBar with a [Dismiss] Button
|
2024-06-14 14:28:59 +02:00
|
|
|
void showErrorSnackBar(BuildContext context, String message) {
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(
|
2024-06-18 02:24:42 +02:00
|
|
|
content: Text(
|
|
|
|
message,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
color: Theme.of(context).colorScheme.onErrorContainer,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.errorContainer,
|
2024-06-14 14:28:59 +02:00
|
|
|
action: SnackBarAction(
|
|
|
|
label: 'Dismiss',
|
2024-06-18 02:24:42 +02:00
|
|
|
textColor: Theme.of(context).colorScheme.primary,
|
2024-06-14 14:28:59 +02:00
|
|
|
onPressed: () {
|
|
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-06-24 04:41:17 +02:00
|
|
|
|
|
|
|
/// Show a confirmation dialog and return [true] on confirm,
|
|
|
|
/// [false] on cancel, or null otherwise.
|
|
|
|
Future<bool?> showConfirmationDialog(
|
|
|
|
BuildContext context, String title, String content) async {
|
|
|
|
bool? confirm = await showDialog<bool>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
|
|
|
title: Text(title),
|
|
|
|
content: Text(content),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => Navigator.of(context).pop(false),
|
|
|
|
child: const Text('Cancel'),
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => Navigator.of(context).pop(true),
|
|
|
|
child: const Text('Confirm'),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
return confirm;
|
|
|
|
}
|