Files
fforte/lib/screens/helper/view_entries_dialog_helper.dart

98 lines
3.3 KiB
Dart

// * Helper class for displaying confirmation dialogs
// * Used when viewing and managing database entries
// * Provides dialogs for deleting entries and templates
import 'package:fforte/enums/databases.dart';
import 'package:fforte/l10n/app_localizations.dart';
import 'package:fforte/screens/sharedMethods/delete_main_entries.dart';
import 'package:fforte/screens/sharedMethods/delete_templates.dart';
import 'package:flutter/material.dart';
/// Helper class for managing confirmation dialogs
/// Contains static methods for showing delete confirmation dialogs
class ViewEntriesDialogHelper {
/// Show confirmation dialog for deleting all main entries
/// @param context The BuildContext to show the dialog in
/// @param dbType The type of database (place/excursion) to delete from
static Future<void> deleteAllMainEntries(
BuildContext context,
DatabasesEnum dbType,
) async {
return showDialog(
context: context,
barrierDismissible: false, // User must make a choice
builder: (BuildContext context) {
return AlertDialog(
title: Text(AppLocalizations.of(context)!.deleteEverything),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text(AppLocalizations.of(context)!.deleteEverythingContent),
],
),
),
actions: <Widget>[
// Delete confirmation button
TextButton(
onPressed: () async {
await DeleteMainEntries.deleteAll(dbType);
if (context.mounted) Navigator.of(context).pop();
},
child: Text(AppLocalizations.of(context)!.deleteEverything),
),
// Cancel button
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(AppLocalizations.of(context)!.cancel),
),
],
);
},
);
}
/// Show confirmation dialog for deleting all templates
/// @param context The BuildContext to show the dialog in
/// @param dbType The type of database (place/excursion) to delete from
static Future<void> deleteAllTemplates(
BuildContext context,
DatabasesEnum dbType,
) async {
return showDialog(
context: context,
barrierDismissible: false, // User must make a choice
builder: (BuildContext context) {
return AlertDialog(
title: Text(AppLocalizations.of(context)!.deleteEverything),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text(AppLocalizations.of(context)!.deleteEverythingContent),
],
),
),
actions: <Widget>[
// Delete confirmation button
TextButton(
onPressed: () async {
await DeleteTemplates.deleteAll(dbType);
if (context.mounted) Navigator.of(context).pop();
},
child: Text(AppLocalizations.of(context)!.deleteEverything),
),
// Cancel button
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(AppLocalizations.of(context)!.cancel),
),
],
);
},
);
}
}