calorimeter/lib/utils/calendar_floating_button.dart

34 lines
1010 B
Dart
Raw Permalink Normal View History

2024-10-06 23:44:19 +00:00
import 'package:calorimeter/utils/date_time_helper.dart';
import 'package:flutter/material.dart';
2024-10-06 23:44:19 +00:00
class CalendarFAB extends StatelessWidget {
final DateTime startFromDate;
final Function(DateTime?) onDateSelected;
2024-10-06 23:44:19 +00:00
const CalendarFAB(
{super.key, required this.startFromDate, required this.onDateSelected});
@override
Widget build(BuildContext context) {
return FloatingActionButton(
onPressed: () async {
var datePicked = await showDatePicker(
locale: const Locale('de'),
context: context,
initialDate: startFromDate,
2024-10-06 23:44:19 +00:00
currentDate: DateTimeHelper.now(),
firstDate:
DateTimeHelper.now().subtract(const Duration(days: 365 * 10)),
lastDate: DateTimeHelper.now().add(const Duration(days: 365 * 10)),
);
if (!context.mounted) return;
2024-10-06 23:44:19 +00:00
onDateSelected(datePicked?.copyWith(isUtc: true));
},
heroTag: "calendarFAB",
2024-10-06 23:44:19 +00:00
child: const Icon(Icons.date_range),
);
}
}