day_table_view.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.currentDate,
  12. });
  13. final List<DateTime> weekdays;
  14. final Function(DateTime)? onSelect;
  15. final DateTime selectedDate;
  16. final DateTime currentDate;
  17. @override
  18. Widget build(BuildContext context) {
  19. return Column(
  20. children: [
  21. // 第一行
  22. Row(
  23. mainAxisAlignment: MainAxisAlignment.spaceAround,
  24. children: weekdays.sublist(0, 7).map(
  25. (date) {
  26. return GestureDetector(
  27. onTap: isPastDate(currentDate, date) ? null : () => onSelect?.call(date),
  28. child: SizedBox(
  29. width: 40,
  30. height: 40,
  31. child: DayCell(
  32. display: date,
  33. selected: selectedDate,
  34. current: currentDate,
  35. ),
  36. ),
  37. );
  38. },
  39. ).toList(),
  40. ),
  41. const SizedBox(height: 10),
  42. // 第二行
  43. Row(
  44. mainAxisAlignment: MainAxisAlignment.spaceAround,
  45. children: weekdays.sublist(7, 14).map(
  46. (date) {
  47. return GestureDetector(
  48. onTap: isPastDate(currentDate, date) ? null : () => onSelect?.call(date),
  49. child: SizedBox(
  50. width: 40,
  51. height: 40,
  52. child: DayCell(
  53. display: date,
  54. selected: selectedDate,
  55. current: currentDate,
  56. ),
  57. ),
  58. );
  59. },
  60. ).toList(),
  61. ),
  62. ],
  63. );
  64. }
  65. }