diff --git a/lib/screens/report_screen.dart b/lib/screens/report_screen.dart index a9803a4..c546259 100644 --- a/lib/screens/report_screen.dart +++ b/lib/screens/report_screen.dart @@ -76,6 +76,7 @@ class _ReportScreenState extends State { Tag? _selectedTag; ReportData? _reportData; bool _isLoadingReport = false; + TimeEntry? _editingEntry; String _formatDuration(Duration duration) { String twoDigits(int n) => n.toString().padLeft(2, "0"); @@ -666,6 +667,13 @@ class _ReportScreenState extends State { icon: Icons.delete, label: 'Löschen', ), + SlidableAction( + onPressed: + (context) => _showEditEntryDialog(context, entry), + backgroundColor: Colors.blue, + icon: Icons.edit, + label: 'Bearbeiten', + ), ], ), child: ListTile( @@ -691,29 +699,169 @@ class _ReportScreenState extends State { ); } - // void _showPlatformFeedbackDialog( - // BuildContext context, - // String title, - // String message, - // ) { - // showPlatformDialog( - // context: context, // Still need context to initiate - // useRootNavigator: - // true, // This might help find a stable navigator ancestor - // builder: - // (dialogContext) => PlatformAlertDialog( - // title: PlatformText(title), - // content: PlatformText(message), - // actions: [ - // PlatformDialogAction( - // child: PlatformText('OK'), - // onPressed: - // () => Navigator.pop( - // dialogContext, - // ), // Pop using dialog's context - // ), - // ], - // ), - // ); - // } + Future _showEditEntryDialog( + BuildContext context, + TimeEntry entry, + ) async { + DateTime? startTime = entry.startDateTime; + DateTime? endTime = entry.endDateTime; + + await showPlatformDialog( + context: context, + builder: (BuildContext context) { + return PlatformAlertDialog( + title: Text('Eintrag bearbeiten'), + content: StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + PlatformText('Startzeit:'), + PlatformElevatedButton( + child: Text( + DateFormat('yyyy-MM-dd HH:mm').format(startTime!), + ), + onPressed: () async { + DateTime? pickedDate = await showPlatformDatePicker( + context: context, + initialDate: startTime!, + firstDate: DateTime(2000), + lastDate: DateTime(2101), + ); + if (pickedDate != null) { + TimeOfDay? pickedTime = await showTimePicker( + context: context, + initialTime: TimeOfDay.fromDateTime(startTime!), + ); + if (pickedTime != null) { + setState(() { + startTime = DateTime( + pickedDate.year, + pickedDate.month, + pickedDate.day, + pickedTime.hour, + pickedTime.minute, + ); + }); + } + } + }, + ), + PlatformText('Endzeit:'), + PlatformElevatedButton( + child: Text( + endTime != null + ? DateFormat('yyyy-MM-dd HH:mm').format(endTime!) + : 'Keine Endzeit', + ), + onPressed: () async { + DateTime? pickedDate = await showPlatformDatePicker( + context: context, + initialDate: endTime ?? DateTime.now(), + firstDate: DateTime(2000), + lastDate: DateTime(2101), + ); + if (pickedDate != null) { + TimeOfDay? pickedTime = await showTimePicker( + context: context, + initialTime: TimeOfDay.fromDateTime( + endTime ?? DateTime.now(), + ), + ); + if (pickedTime != null) { + setState(() { + endTime = DateTime( + pickedDate.year, + pickedDate.month, + pickedDate.day, + pickedTime.hour, + pickedTime.minute, + ); + }); + } + } + }, + ), + ], + ); + }, + ), + actions: [ + PlatformDialogAction( + child: PlatformText('Abbrechen'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + PlatformDialogAction( + child: PlatformText('Speichern'), + onPressed: () async { + // Hier die Logik zum Speichern der bearbeiteten Daten + Navigator.of(context).pop(); + _updateTimeEntry(entry, startTime, endTime); + }, + ), + ], + ); + }, + ); + } + + Future _updateTimeEntry( + TimeEntry entry, + DateTime? startTime, + DateTime? endTime, + ) async { + final timeService = Provider.of( + context, + listen: false, + ); + + if (startTime == null || endTime == null) { + log("Start- oder Endzeit darf nicht null sein."); + return; + } + + bool success = await timeService.flUpdateTimeEntry( + entryId: entry.id, + tagId: entry.tagId, + startTime: startTime, + endTime: endTime, + ); + + if (success) { + _generateReport(); + } else { + _showPlatformFeedbackDialog( + context, + 'Error', + 'Fehler beim Aktualisieren des TimeEntry.', + ); + } + } + + void _showPlatformFeedbackDialog( + BuildContext context, + String title, + String message, + ) { + showPlatformDialog( + context: context, + useRootNavigator: true, + builder: + (dialogContext) => PlatformAlertDialog( + title: PlatformText(title), + content: PlatformText(message), + actions: [ + PlatformDialogAction( + child: PlatformText('OK'), + onPressed: + () => Navigator.pop( + dialogContext, + ), // Pop using dialog's context + ), + ], + ), + ); + } } diff --git a/pubspec.yaml b/pubspec.yaml index af373e5..69c0961 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,11 +15,11 @@ dependencies: rust_lib_timetracker: path: rust_builder flutter_rust_bridge: 2.9.0 - ffi: ^2.1.0 # Für FFI - path_provider: ^2.1.1 # Um das App-Datenverzeichnis zu finden - intl: ^0.20.2 # Für Datums-/Zeitformatierung - provider: ^6.1.1 # Beispiel für State Management - fl_chart: ^0.70.2 # Für Charts im Report + ffi: ^2.1.0 + path_provider: ^2.1.1 + intl: ^0.20.2 + provider: ^6.1.1 + fl_chart: ^0.70.2 flutter_platform_widgets: ^8.0.0 flutter_slidable: ^4.0.0 @@ -27,7 +27,6 @@ dev_dependencies: flutter_test: sdk: flutter - # flutter_rust_bridge_codegen: 2.9.0 flutter_lints: ^5.0.0 integration_test: sdk: flutter