let AI comment everything because well... yeah...

This commit is contained in:
Nico
2025-06-06 21:00:32 +02:00
parent 9c84d0c375
commit cc110ac104
44 changed files with 1230 additions and 646 deletions

View File

@@ -1,3 +1,11 @@
// * Helper class for managing entry-related dialogs
// * Provides various dialog types:
// * - Template creation dialog
// * - Save options dialog
// * - Server error handling dialog
// * - Location settings dialog
// * - Route deletion confirmation dialog
import 'package:fforte/enums/databases.dart';
import 'package:fforte/screens/helper/snack_bar_helper.dart';
import 'package:fforte/screens/sharedMethods/http_request.dart';
@@ -8,8 +16,12 @@ import 'package:flutter/material.dart';
import 'package:fforte/l10n/app_localizations.dart';
import 'package:geolocator/geolocator.dart';
/// Helper class for managing various dialogs related to adding and saving entries
class AddEntriesDialogHelper {
// Function to show the dialog where the user has to choose if he want to safe his values as a template
/// Show dialog for saving current data as a template
/// @param context The BuildContext to show the dialog in
/// @param saveData Map containing the data to save
/// @param dbType The type of database (place/excursion)
static Future<void> showTemplateDialog(
BuildContext context,
Map<String, String> saveData,
@@ -17,17 +29,19 @@ class AddEntriesDialogHelper {
) async {
return showDialog(
context: context,
barrierDismissible: false,
barrierDismissible: false, // User must make a choice
builder: (BuildContext context) {
return AlertDialog(
title: Text(AppLocalizations.of(context)!.fieldEmpty),
actions: <Widget>[
// Cancel button
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(AppLocalizations.of(context)!.cancel),
),
// Save as template button
TextButton(
onPressed: () {
saveTemplate(saveData, dbType);
@@ -45,6 +59,12 @@ class AddEntriesDialogHelper {
);
}
/// Show error dialog when server communication fails
/// Offers options to retry or cancel
/// @param context The BuildContext to show the dialog in
/// @param saveData Map containing the data to save
/// @param isTemplate Whether this is a template entry
/// @param dbType The type of database (place/excursion)
static Future<dynamic> showServerErrorDialog(
BuildContext context,
Map<String, String> saveData,
@@ -68,6 +88,7 @@ class AddEntriesDialogHelper {
)
: null,
actions: [
// Retry button
if (!isLoading)
TextButton(
onPressed: () async {
@@ -79,19 +100,18 @@ class AddEntriesDialogHelper {
if (errorCode == 200 && context.mounted) {
Navigator.pop(context);
// saveData(true);
SaveMainEntryMethod.saveEntry(
entryData: saveData,
isTemplate: isTemplate,
dbType: dbType,
sent: true
);
showSuccessDialog(context);
}
},
child: Text(AppLocalizations.of(context)!.sendagain),
),
// Cancel button
if (!isLoading)
TextButton(
onPressed: () {
@@ -107,6 +127,17 @@ class AddEntriesDialogHelper {
);
}
/// Show dialog with various save options
/// Options include:
/// - Save as template
/// - Send to server
/// - Save as file
/// - Save locally only
/// @param context The BuildContext to show the dialog in
/// @param saveData Map containing the data to save
/// @param isTemplate Whether this is a template entry
/// @param dbType The type of database (place/excursion)
/// @return bool Whether the operation was completed successfully
static Future<bool> showSaveOptionsDialog(
BuildContext context,
Map<String, String> saveData,
@@ -118,7 +149,7 @@ class AddEntriesDialogHelper {
await showDialog(
context: context,
barrierDismissible: false,
barrierDismissible: false, // User must make a choice
builder: (BuildContext context) {
return StatefulBuilder(
builder: (context, setState) {
@@ -135,6 +166,7 @@ class AddEntriesDialogHelper {
)
: null,
actions: [
// Save as template button
if (!isLoading)
TextButton(
onPressed: () async {
@@ -156,6 +188,7 @@ class AddEntriesDialogHelper {
},
child: Text(AppLocalizations.of(context)!.template),
),
// Send to server button
if (!isLoading)
TextButton(
onPressed: () async {
@@ -192,6 +225,7 @@ class AddEntriesDialogHelper {
},
child: Text(AppLocalizations.of(context)!.sendtoserver),
),
// Save as file button
if (!isLoading)
TextButton(
onPressed: () async {
@@ -223,7 +257,7 @@ class AddEntriesDialogHelper {
pop = true;
}
} catch (_) {
// User cancelled the dialog
// User cancelled the file save dialog
}
setState(() => isLoading = false);
} catch (e) {
@@ -238,6 +272,7 @@ class AddEntriesDialogHelper {
},
child: Text(AppLocalizations.of(context)!.saveasfile),
),
// Save locally only button
if (!isLoading)
TextButton(
onPressed: () {
@@ -265,6 +300,7 @@ class AddEntriesDialogHelper {
},
child: Text(AppLocalizations.of(context)!.justsave),
),
// Cancel button
if (!isLoading)
TextButton(
onPressed: () {
@@ -282,6 +318,8 @@ class AddEntriesDialogHelper {
return pop;
}
/// Show success dialog after successful save operation
/// @param context The BuildContext to show the dialog in
static Future<void> showSuccessDialog(BuildContext context) async {
return showDialog(
context: context,
@@ -305,8 +343,10 @@ class AddEntriesDialogHelper {
);
}
/// Show dialog requesting location permission settings
/// @param context The BuildContext to show the dialog in
/// @return bool Whether the settings were changed
static Future<bool> locationSettingsDialog(BuildContext context) async {
bool reload = false;
await showDialog(
@@ -316,6 +356,7 @@ class AddEntriesDialogHelper {
return AlertDialog(
content: Text(AppLocalizations.of(context)!.needsAlwaysLocation),
actions: [
// Open settings button
TextButton(
onPressed: () async {
await Geolocator.openAppSettings();
@@ -324,6 +365,7 @@ class AddEntriesDialogHelper {
},
child: Text("Ok"),
),
// Cancel button
TextButton(
onPressed: () {
Navigator.of(context).pop();
@@ -337,6 +379,9 @@ class AddEntriesDialogHelper {
return reload;
}
/// Show confirmation dialog for deleting entire route
/// @param context The BuildContext to show the dialog in
/// @return bool Whether deletion was confirmed
static Future<bool> deleteCompleteRouteDialog(BuildContext context) async {
bool confirmed = false;
@@ -354,6 +399,7 @@ class AddEntriesDialogHelper {
),
),
actions: [
// Confirm delete button
TextButton(
onPressed: () {
confirmed = true;
@@ -361,6 +407,7 @@ class AddEntriesDialogHelper {
},
child: Text("Ok"),
),
// Cancel button
TextButton(
onPressed: () => {Navigator.of(context).pop()},
child: Text(AppLocalizations.of(context)!.cancel),

View File

@@ -1,6 +1,15 @@
// * Helper class for displaying snackbar messages
// * Provides a consistent way to show temporary notifications
// * throughout the app
import 'package:flutter/material.dart';
/// Utility class for showing snackbar messages
/// Contains static methods to display notifications
class SnackBarHelper {
/// Display a snackbar message at the bottom of the screen
/// @param context The BuildContext to show the snackbar in
/// @param message The text message to display
static void showSnackBarMessage(BuildContext context, String message) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(message)));

View File

@@ -1,17 +1,26 @@
// * 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,
barrierDismissible: false, // User must make a choice
builder: (BuildContext context) {
return AlertDialog(
title: Text(AppLocalizations.of(context)!.deleteEverything),
@@ -23,14 +32,15 @@ class ViewEntriesDialogHelper {
),
),
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();
@@ -43,13 +53,16 @@ class ViewEntriesDialogHelper {
);
}
/// 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,
barrierDismissible: false, // User must make a choice
builder: (BuildContext context) {
return AlertDialog(
title: Text(AppLocalizations.of(context)!.deleteEverything),
@@ -61,6 +74,7 @@ class ViewEntriesDialogHelper {
),
),
actions: <Widget>[
// Delete confirmation button
TextButton(
onPressed: () async {
await DeleteTemplates.deleteAll(dbType);
@@ -68,6 +82,7 @@ class ViewEntriesDialogHelper {
},
child: Text(AppLocalizations.of(context)!.deleteEverything),
),
// Cancel button
TextButton(
onPressed: () {
Navigator.of(context).pop();
@@ -79,5 +94,4 @@ class ViewEntriesDialogHelper {
},
);
}
}