// * Widget for managing camera trap dismantling dates // * Features: // * - Date picker for selecting dismantling date // * - Date display and reset functionality // * - Localized text support import 'package:flutter/material.dart'; import 'package:fforte/l10n/app_localizations.dart'; /// Widget for selecting and displaying camera trap dismantling dates /// Allows users to pick a date or clear the selection class AbbauDat extends StatefulWidget { /// Initial dismantling date, can be null if not set final DateTime? initAbbauDat; /// Callback function when date is changed final Function(DateTime) onDateChanged; const AbbauDat({super.key, required this.initAbbauDat, required this.onDateChanged}); @override State createState() => _AbbauDatState(); } /// State class for the dismantling date widget class _AbbauDatState extends State { /// Currently selected dismantling date DateTime? abbauDat; @override void initState() { super.initState(); abbauDat = widget.initAbbauDat; } @override Widget build(BuildContext context) { return Row( children: [ Column(children: [ // Date picker button SizedBox( width: 140, child: ElevatedButton( onPressed: () async { final date = await pickDate(); if (date == null) return; setState(() => abbauDat = date); widget.onDateChanged(date); }, child: Text(AppLocalizations.of(context)!.pickabbaudat)), ), Row( children: [ const SizedBox(width: 10), // Display selected date or "nothing" text Builder(builder: (context) { if (abbauDat != null) { return Text( '${abbauDat?.day}. ${abbauDat?.month}. ${abbauDat?.year}'); } else { return Text(AppLocalizations.of(context)!.nichts); } }), const SizedBox(width: 10), // Clear date button ElevatedButton( onPressed: () { setState(() { abbauDat = null; }); }, child: const Text("X")) ]), ], ) ], ); } /// Show date picker dialog and return selected date /// @return Future[DateTime?] Selected date or null if cancelled Future pickDate() async { final date = await showDatePicker( context: context, initialDate: DateTime.now(), firstDate: DateTime(2000), lastDate: DateTime(5000)); if (date == null) return null; return date; } }