1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import 'package:flutter/material.dart';
- import 'calendar_utils.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(currentDate, 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(currentDate, date) ? null : () => onSelect?.call(date),
- child: SizedBox(
- width: 40,
- height: 40,
- child: DayCell(
- display: date,
- selected: selectedDate,
- current: currentDate,
- ),
- ),
- );
- },
- ).toList(),
- ),
- ],
- );
- }
- }
|