calorimeter/lib/utils/calendar_floating_button.dart
2024-10-08 01:04:33 +02:00

34 lines
1010 B
Dart

import 'package:calorimeter/utils/date_time_helper.dart';
import 'package:flutter/material.dart';
class CalendarFAB extends StatelessWidget {
final DateTime startFromDate;
final Function(DateTime?) onDateSelected;
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,
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;
onDateSelected(datePicked?.copyWith(isUtc: true));
},
heroTag: "calendarFAB",
child: const Icon(Icons.date_range),
);
}
}