day_table_view.dart 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'package:flutter/material.dart';
  2. import 'calendar_utils.dart';
  3. import 'day_cell.dart';
  4. /// 一周的数据为一行,展示两周共两行
  5. class DayTableView extends StatelessWidget {
  6. const DayTableView({
  7. super.key,
  8. required this.weekdays,
  9. required this.onSelect,
  10. required this.selectedDate,
  11. required this.maxDate,
  12. required this.currentDate,
  13. });
  14. final List<DateTime> weekdays;
  15. final Function(DateTime)? onSelect;
  16. final DateTime selectedDate;
  17. final DateTime maxDate;
  18. final DateTime currentDate;
  19. @override
  20. Widget build(BuildContext context) {
  21. return Column(
  22. children: [
  23. // 第一行
  24. Row(
  25. mainAxisAlignment: MainAxisAlignment.spaceAround,
  26. children: weekdays.sublist(0, 7).map(
  27. (date) {
  28. return GestureDetector(
  29. onTap: isPastDate(currentDate, date) || isAfterMaxDate(maxDate, date) ? null : () => onSelect?.call(date),
  30. child: SizedBox(
  31. width: 40,
  32. height: 40,
  33. child: DayCell(
  34. display: date,
  35. selected: selectedDate,
  36. maxDate: maxDate,
  37. current: currentDate,
  38. ),
  39. ),
  40. );
  41. },
  42. ).toList(),
  43. ),
  44. const SizedBox(height: 10),
  45. // 第二行
  46. Row(
  47. mainAxisAlignment: MainAxisAlignment.spaceAround,
  48. children: weekdays.sublist(7, 14).map(
  49. (date) {
  50. return GestureDetector(
  51. onTap: isPastDate(currentDate, date) || isAfterMaxDate(maxDate, date) ? null : () => onSelect?.call(date),
  52. child: SizedBox(
  53. width: 40,
  54. height: 40,
  55. child: DayCell(
  56. display: date,
  57. selected: selectedDate,
  58. maxDate: maxDate,
  59. current: currentDate,
  60. ),
  61. ),
  62. );
  63. },
  64. ).toList(),
  65. ),
  66. ],
  67. );
  68. }
  69. }