| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; |
| 3 | import 'package:aero/formatters/time.dart'; |
| 4 | |
| 5 | class DateSelectionList extends StatelessWidget |
| 6 | final Function(DateTime |
| 7 | |
| 8 | const DateSelectionList({ |
| 9 | super.key, |
| 10 | required this.onDateSelected, |
| 11 | }); |
| 12 | |
| 13 | @override |
| 14 | Widget build(BuildContext |
| 15 | return ListView.builder |
| 16 | itemBuilder: (context, index) { |
| 17 | final date = DateTime. |
| 18 | if (index == 0) { |
| 19 | return ListTile( |
| 20 | title: Text("Today"), |
| 21 | leading: Icon(Icons. |
| 22 | subtitle: Text(formatDayAndMonth(date)) |
| 23 | onTap: () => onDateSelected(date), |
| 24 | ); |
| 25 | } else if (index == 1) { |
| 26 | final tmrh = DateTime(date |
| 27 | return ListTile( |
| 28 | title: Text("Tomorrow"), |
| 29 | leading: Icon(MdiIcons. |
| 30 | subtitle: Text(formatDayAndMonth(tmrh)) |
| 31 | onTap: () => onDateSelected(tmrh), |
| 32 | ); |
| 33 | } else if (index == 2) { |
| 34 | final yesterday = DateTime(date |
| 35 | return ListTile( |
| 36 | title: Text("Yesterday"), |
| 37 | leading: Icon(MdiIcons. |
| 38 | subtitle: Text(formatDayAndMonth(yesterday)) |
| 39 | onTap: () => onDateSelected(yesterday), |
| 40 | ); |
| 41 | } else { |
| 42 | return ListTile( |
| 43 | title: Text("Select from calendar"), |
| 44 | leading: Icon(MdiIcons. |
| 45 | onTap: () async { |
| 46 | final selectedDate = await showDatePicker |
| 47 | context: context, |
| 48 | initialDate: date, |
| 49 | firstDate: date.subtract(Duration |
| 50 | lastDate: date.add(Duration |
| 51 | ); |
| 52 | if (selectedDate != null) { |
| 53 | onDateSelected(selectedDate); |
| 54 | } |
| 55 | }, |
| 56 | ); |
| 57 | } |
| 58 | }, |
| 59 | shrinkWrap: true, |
| 60 | padding: EdgeInsets.zero, |
| 61 | itemCount: 4, |
| 62 | ); |
| 63 | } |
| 64 | } |
| 65 | |