refactor: clean up
This commit is contained in:
parent
18e07dcb6d
commit
ef130fa83c
2 changed files with 178 additions and 31 deletions
|
|
@ -76,6 +76,7 @@ class _ReportScreenState extends State<ReportScreen> {
|
||||||
Tag? _selectedTag;
|
Tag? _selectedTag;
|
||||||
ReportData? _reportData;
|
ReportData? _reportData;
|
||||||
bool _isLoadingReport = false;
|
bool _isLoadingReport = false;
|
||||||
|
TimeEntry? _editingEntry;
|
||||||
|
|
||||||
String _formatDuration(Duration duration) {
|
String _formatDuration(Duration duration) {
|
||||||
String twoDigits(int n) => n.toString().padLeft(2, "0");
|
String twoDigits(int n) => n.toString().padLeft(2, "0");
|
||||||
|
|
@ -666,6 +667,13 @@ class _ReportScreenState extends State<ReportScreen> {
|
||||||
icon: Icons.delete,
|
icon: Icons.delete,
|
||||||
label: 'Löschen',
|
label: 'Löschen',
|
||||||
),
|
),
|
||||||
|
SlidableAction(
|
||||||
|
onPressed:
|
||||||
|
(context) => _showEditEntryDialog(context, entry),
|
||||||
|
backgroundColor: Colors.blue,
|
||||||
|
icon: Icons.edit,
|
||||||
|
label: 'Bearbeiten',
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
|
|
@ -691,29 +699,169 @@ class _ReportScreenState extends State<ReportScreen> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void _showPlatformFeedbackDialog(
|
Future<void> _showEditEntryDialog(
|
||||||
// BuildContext context,
|
BuildContext context,
|
||||||
// String title,
|
TimeEntry entry,
|
||||||
// String message,
|
) async {
|
||||||
// ) {
|
DateTime? startTime = entry.startDateTime;
|
||||||
// showPlatformDialog(
|
DateTime? endTime = entry.endDateTime;
|
||||||
// context: context, // Still need context to initiate
|
|
||||||
// useRootNavigator:
|
await showPlatformDialog(
|
||||||
// true, // This might help find a stable navigator ancestor
|
context: context,
|
||||||
// builder:
|
builder: (BuildContext context) {
|
||||||
// (dialogContext) => PlatformAlertDialog(
|
return PlatformAlertDialog(
|
||||||
// title: PlatformText(title),
|
title: Text('Eintrag bearbeiten'),
|
||||||
// content: PlatformText(message),
|
content: StatefulBuilder(
|
||||||
// actions: <Widget>[
|
builder: (BuildContext context, StateSetter setState) {
|
||||||
// PlatformDialogAction(
|
return Column(
|
||||||
// child: PlatformText('OK'),
|
mainAxisSize: MainAxisSize.min,
|
||||||
// onPressed:
|
children: <Widget>[
|
||||||
// () => Navigator.pop(
|
PlatformText('Startzeit:'),
|
||||||
// dialogContext,
|
PlatformElevatedButton(
|
||||||
// ), // Pop using dialog's context
|
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<void> _updateTimeEntry(
|
||||||
|
TimeEntry entry,
|
||||||
|
DateTime? startTime,
|
||||||
|
DateTime? endTime,
|
||||||
|
) async {
|
||||||
|
final timeService = Provider.of<TimeTrackingService>(
|
||||||
|
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: <Widget>[
|
||||||
|
PlatformDialogAction(
|
||||||
|
child: PlatformText('OK'),
|
||||||
|
onPressed:
|
||||||
|
() => Navigator.pop(
|
||||||
|
dialogContext,
|
||||||
|
), // Pop using dialog's context
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
pubspec.yaml
11
pubspec.yaml
|
|
@ -15,11 +15,11 @@ dependencies:
|
||||||
rust_lib_timetracker:
|
rust_lib_timetracker:
|
||||||
path: rust_builder
|
path: rust_builder
|
||||||
flutter_rust_bridge: 2.9.0
|
flutter_rust_bridge: 2.9.0
|
||||||
ffi: ^2.1.0 # Für FFI
|
ffi: ^2.1.0
|
||||||
path_provider: ^2.1.1 # Um das App-Datenverzeichnis zu finden
|
path_provider: ^2.1.1
|
||||||
intl: ^0.20.2 # Für Datums-/Zeitformatierung
|
intl: ^0.20.2
|
||||||
provider: ^6.1.1 # Beispiel für State Management
|
provider: ^6.1.1
|
||||||
fl_chart: ^0.70.2 # Für Charts im Report
|
fl_chart: ^0.70.2
|
||||||
flutter_platform_widgets: ^8.0.0
|
flutter_platform_widgets: ^8.0.0
|
||||||
flutter_slidable: ^4.0.0
|
flutter_slidable: ^4.0.0
|
||||||
|
|
||||||
|
|
@ -27,7 +27,6 @@ dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
||||||
# flutter_rust_bridge_codegen: 2.9.0
|
|
||||||
flutter_lints: ^5.0.0
|
flutter_lints: ^5.0.0
|
||||||
integration_test:
|
integration_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue