2024-12-07 12:29:34 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
2024-12-07 12:39:11 +00:00
|
|
|
/* Copyright (C) 2024 Marco Groß <mgross@sw-gross.de> */
|
2024-10-06 23:44:19 +00:00
|
|
|
import 'package:calorimeter/utils/date_time_helper.dart';
|
2024-06-10 01:06:56 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2024-10-06 23:44:19 +00:00
|
|
|
class CalendarFAB extends StatelessWidget {
|
2024-09-06 23:38:03 +00:00
|
|
|
final DateTime startFromDate;
|
2024-10-03 21:21:13 +00:00
|
|
|
final Function(DateTime?) onDateSelected;
|
2024-06-10 01:06:56 +00:00
|
|
|
|
2024-10-06 23:44:19 +00:00
|
|
|
const CalendarFAB(
|
2024-09-06 23:38:03 +00:00
|
|
|
{super.key, required this.startFromDate, required this.onDateSelected});
|
2024-06-10 01:06:56 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FloatingActionButton(
|
2024-09-06 23:38:03 +00:00
|
|
|
onPressed: () async {
|
|
|
|
var datePicked = await showDatePicker(
|
|
|
|
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)),
|
2024-09-06 23:38:03 +00:00
|
|
|
);
|
2024-06-10 01:06:56 +00:00
|
|
|
|
2024-09-06 23:38:03 +00:00
|
|
|
if (!context.mounted) return;
|
|
|
|
|
2024-10-06 23:44:19 +00:00
|
|
|
onDateSelected(datePicked?.copyWith(isUtc: true));
|
2024-09-06 23:38:03 +00:00
|
|
|
},
|
|
|
|
heroTag: "calendarFAB",
|
2024-10-06 23:44:19 +00:00
|
|
|
child: const Icon(Icons.date_range),
|
2024-09-06 23:38:03 +00:00
|
|
|
);
|
2024-06-10 01:06:56 +00:00
|
|
|
}
|
|
|
|
}
|