calorimeter/lib/utils/calendar_floating_button.dart

35 lines
1.1 KiB
Dart
Raw Permalink Normal View History

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';
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(
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),
);
}
}