123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import 'package:flutter/material.dart';
- import 'day_cell.dart';
- /// 一周的数据为一行,展示两周共两行
- class DayTableView extends StatelessWidget {
- const DayTableView({
- super.key,
- required this.weekdays,
- required this.onSelect,
- required this.selectedDate,
- required this.currentDate,
- });
- final List<DateTime> weekdays;
- final Function(DateTime)? onSelect;
- final DateTime selectedDate;
- final DateTime currentDate;
- @override
- Widget build(BuildContext context) {
- return Column(
- children: [
- // 第一行
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: weekdays.sublist(0, 7).map(
- (date) {
- return GestureDetector(
- onTap: _isPastDate(date) ? null : () => onSelect?.call(date),
- child: SizedBox(
- width: 40,
- height: 40,
- child: DayCell(
- display: date,
- selected: selectedDate,
- current: currentDate,
- ),
- ),
- );
- },
- ).toList(),
- ),
- const SizedBox(height: 10),
- // 第二行
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: weekdays.sublist(7, 14).map(
- (date) {
- return GestureDetector(
- onTap: _isPastDate(date) ? null : () => onSelect?.call(date),
- child: SizedBox(
- width: 40,
- height: 40,
- child: DayCell(
- display: date,
- selected: selectedDate,
- current: currentDate,
- ),
- ),
- );
- },
- ).toList(),
- ),
- ],
- );
- }
- // 检查日期是否小于今天
- bool _isPastDate(DateTime date) {
- return date.isBefore(DateTime.now().subtract(const Duration(days: 1))); // 小于今天
- }
- }
|