77 lines
2.1 KiB
Dart
77 lines
2.1 KiB
Dart
// * Widget for managing camera trap control/check dates
|
|
// * Features:
|
|
// * - Date picker for selecting control dates
|
|
// * - Date display in localized format
|
|
// * - Callback support for date changes
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:fforte/l10n/app_localizations.dart';
|
|
|
|
/// Widget for selecting and displaying camera trap control dates
|
|
/// Used to schedule when the camera trap should be checked
|
|
class KontDat extends StatefulWidget {
|
|
/// Initial control date, if any
|
|
final DateTime? initKontDat;
|
|
/// Callback function when date is changed
|
|
final Function(DateTime) onDateChanged;
|
|
|
|
const KontDat(
|
|
{super.key, required this.initKontDat, required this.onDateChanged});
|
|
|
|
@override
|
|
State<KontDat> createState() => _KontDatState();
|
|
}
|
|
|
|
/// State class for the control date widget
|
|
class _KontDatState extends State<KontDat> {
|
|
/// Currently selected control date
|
|
DateTime? kontDat;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
kontDat = widget.initKontDat;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
children: [
|
|
Row(children: [
|
|
// Date picker button
|
|
SizedBox(
|
|
width: 140,
|
|
child: ElevatedButton(
|
|
onPressed: () async {
|
|
final date = await pickDate();
|
|
if (date == null) return;
|
|
setState(() {
|
|
kontDat = date;
|
|
});
|
|
widget.onDateChanged(date);
|
|
},
|
|
child: Text(AppLocalizations.of(context)!.pickkontdat)),
|
|
),
|
|
const SizedBox(width: 10),
|
|
// Display selected date in DD.MM.YYYY format
|
|
Text(
|
|
'${kontDat?.day}. ${kontDat?.month}. ${kontDat?.year}',
|
|
),
|
|
]),
|
|
],
|
|
);
|
|
}
|
|
|
|
/// Show date picker dialog and return selected date
|
|
/// @return Future[DateTime?] Selected date or null if cancelled
|
|
Future<DateTime?> pickDate() async {
|
|
final date = await showDatePicker(
|
|
context: context,
|
|
initialDate: kontDat ?? DateTime.now(),
|
|
firstDate: DateTime(2000),
|
|
lastDate: DateTime(5000));
|
|
|
|
return date;
|
|
}
|
|
}
|