added frontend
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:fotodocumentation/main.dart' show logger;
|
||||
import 'package:fotodocumentation/l10n/app_localizations.dart';
|
||||
import 'package:fotodocumentation/pages/ui_utils/dialog/snackbar_utils.dart';
|
||||
import 'package:fotodocumentation/utils/di_container.dart';
|
||||
|
||||
class DeleteDialog extends StatelessWidget {
|
||||
static SnackbarUtils get _snackbarUtils => DiContainer.get();
|
||||
|
||||
const DeleteDialog({super.key});
|
||||
|
||||
static Future<void> show(BuildContext context, Future<DeleteDialogResult> Function() doDelete) async {
|
||||
await _openDialog(context).then((value) async {
|
||||
if (value != null && value && context.mounted) {
|
||||
logger.d("Delete popup result $value");
|
||||
var result = await doDelete();
|
||||
if (context.mounted && result.msg.isNotEmpty) {
|
||||
_snackbarUtils.showSnackbar(context, result.msg, result.warning);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static Future<bool?> _openDialog(BuildContext context) async {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false, // user must tap button!
|
||||
builder: (BuildContext context) {
|
||||
return const DeleteDialog(
|
||||
key: Key("delete_dialog"),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
return AlertDialog(
|
||||
backgroundColor: Colors.white,
|
||||
scrollable: false,
|
||||
titlePadding: const EdgeInsets.all(16.0),
|
||||
contentPadding: const EdgeInsets.fromLTRB(16.0, 0, 16.0, 16.0),
|
||||
title: _titleWidget(context, loc),
|
||||
content: _content(context, loc),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _titleWidget(BuildContext context, AppLocalizations loc) {
|
||||
return Card(
|
||||
elevation: 4,
|
||||
margin: EdgeInsets.zero,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
side: BorderSide(
|
||||
color: Colors.grey[300]!,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.warning_amber_rounded,
|
||||
size: 32,
|
||||
color: Colors.orange[700],
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Text(
|
||||
loc.deleteDialogTitle,
|
||||
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
IconButton(
|
||||
key: const Key("close_button"),
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _content(BuildContext context, AppLocalizations loc) {
|
||||
return SizedBox(
|
||||
width: 400,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Card(
|
||||
elevation: 2,
|
||||
margin: EdgeInsets.zero,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
side: BorderSide(
|
||||
color: Colors.grey[300]!,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.warning_amber_rounded,
|
||||
size: 48,
|
||||
color: Colors.orange[700],
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Text(
|
||||
loc.deleteDialogText,
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
key: const Key("delete_dialog:cancel"),
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: Text(loc.deleteDialogButtonCancel),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ElevatedButton.icon(
|
||||
key: const Key("delete_dialog:approve"),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||
backgroundColor: Colors.red[600],
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
icon: const Icon(Icons.delete, size: 20),
|
||||
label: Text(loc.deleteDialogButtonApprove),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DeleteDialogResult {
|
||||
final String msg;
|
||||
final bool warning;
|
||||
|
||||
DeleteDialogResult({required this.msg, required this.warning});
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class DialogResult<T> {
|
||||
final DialogResultType type;
|
||||
final T? dto;
|
||||
|
||||
const DialogResult({required this.type, this.dto});
|
||||
}
|
||||
|
||||
enum DialogResultType {
|
||||
create,
|
||||
add;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
abstract interface class SnackbarUtils {
|
||||
void showSnackbar(BuildContext context, String msg, bool warning);
|
||||
void showSnackbarPopup(BuildContext context, String msg, bool warning);
|
||||
}
|
||||
|
||||
class SnackbarUtilsImpl implements SnackbarUtils {
|
||||
@override
|
||||
void showSnackbar(BuildContext context, String msg, bool warning) {
|
||||
var snackBar = SnackBar(
|
||||
content: _contentFor(context, msg, warning),
|
||||
backgroundColor: Colors.white,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
showCloseIcon: true,
|
||||
closeIconColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
side: BorderSide(width: 2.0, style: BorderStyle.solid, color: Theme.of(context).colorScheme.inversePrimary),
|
||||
),
|
||||
margin: EdgeInsets.only(bottom: MediaQuery.of(context).size.height - 130, left: MediaQuery.of(context).size.width - 400, right: 10),
|
||||
);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
}
|
||||
|
||||
@override
|
||||
void showSnackbarPopup(BuildContext context, String msg, bool warning) {
|
||||
var snackBar = SnackBar(
|
||||
content: _contentFor(context, msg, warning),
|
||||
backgroundColor: Colors.white,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
showCloseIcon: true,
|
||||
closeIconColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
side: BorderSide(width: 2.0, style: BorderStyle.solid, color: Theme.of(context).colorScheme.inversePrimary),
|
||||
),
|
||||
width: 350,
|
||||
//margin: EdgeInsets.only(bottom: MediaQuery.of(context).size.height - 100, left: MediaQuery.of(context).size.width - 350, right: 10),
|
||||
);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
}
|
||||
|
||||
Widget _contentFor(BuildContext context, String msg, bool warning) {
|
||||
var icon = _iconFor(context, warning);
|
||||
|
||||
var style = _textStyleFor(context, warning);
|
||||
return Wrap(
|
||||
alignment: WrapAlignment.start,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
icon,
|
||||
Text(
|
||||
msg,
|
||||
style: style,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Icon _iconFor(BuildContext context, bool warning) {
|
||||
var color = _contentColor(context, warning);
|
||||
return warning ? Icon(Icons.error, color: color) : Icon(Icons.check_circle_outline, color: color);
|
||||
}
|
||||
|
||||
TextStyle _textStyleFor(BuildContext context, bool warning) {
|
||||
var color = _contentColor(context, warning);
|
||||
var bodyLarge = Theme.of(context).primaryTextTheme.bodyLarge!;
|
||||
var style = TextStyle(
|
||||
color: color,
|
||||
decoration: bodyLarge.decoration,
|
||||
fontFamily: bodyLarge.fontFamily,
|
||||
fontSize: bodyLarge.fontSize,
|
||||
fontWeight: bodyLarge.fontWeight,
|
||||
letterSpacing: bodyLarge.letterSpacing,
|
||||
textBaseline: bodyLarge.textBaseline);
|
||||
return style;
|
||||
}
|
||||
|
||||
Color _contentColor(BuildContext context, bool warning) {
|
||||
return warning ? Theme.of(context).colorScheme.error : Theme.of(context).colorScheme.inversePrimary;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user