Line data Source code
1 : import 'package:alh_calendar/enums/day_of_week.dart'; 2 : import 'package:alh_calendar/models/calendar_month.dart'; 3 : import 'package:alh_calendar/utils/calendar_table_helper.dart'; 4 : import 'package:alh_calendar/widgets/alh_calendar.dart'; 5 : import 'package:flutter/cupertino.dart'; 6 : 7 : /// Represents the whole TableView of the calendar. 8 : class CalendarBody extends StatelessWidget { 9 : /// The CalendarMonth that is shown inside the table. 10 : final CalendarMonth calendarMonth; 11 : 12 : /// Custom Builder for a day cell. 13 : final DayBuilder dayBuilder; 14 : 15 : /// Custom Builder for the DayOfWeek cell. 16 : final DayOfWeekBuilder dayOfWeekBuilder; 17 : 18 : /// Callback when value of currentDate hase been changed. 19 : final ValueChanged<DateTime> onSelectDay; 20 : 21 : /// Uses a Map of <DayOfWeek, String> to fill DayOfWeekCalendarCells 22 : /// 23 : /// example: 24 : /// final dayOfWeekMap = { 25 : /// DayOfWeek.monday: 'Mon', 26 : /// DayOfWeek.thursday: 'Thu', 27 : /// DayOfWeek.wednesday: 'Wen', 28 : /// DayOfWeek.tuesday: 'Tue', 29 : /// DayOfWeek.friday: 'Fri', 30 : /// DayOfWeek.saturday: 'Sat', 31 : /// DayOfWeek.sunday: 'Sun', 32 : /// }; 33 : final Map<DayOfWeek, String> daysOfWeek; 34 : 35 : /// The date which is selected at the moment. 36 : final DateTime selectedDateTime; 37 : 38 : /// If true the days outside of the Range can“t be tapped. 39 : final bool disableClickOnOutOfRange; 40 : 41 : /// Disables last Row if there are only days from next month shown in the last row. 42 : /// 43 : /// If true the last Row will be invisible and not tappable, 44 : /// if there are only days from next month shown in the last row. 45 : final bool disableSixthRow; 46 : 47 : /// All days before chosen minimumDayDate are flagged as outOfRange. 48 : final DateTime? minimumDayDate; 49 : 50 : /// All days after chosen maximumDayDate are flagged as outOfRange. 51 : final DateTime? maximumDayDate; 52 : 53 2 : const CalendarBody({ 54 : required this.calendarMonth, 55 : required this.dayBuilder, 56 : required this.dayOfWeekBuilder, 57 : required this.onSelectDay, 58 : required this.daysOfWeek, 59 : required this.selectedDateTime, 60 : required this.disableClickOnOutOfRange, 61 : required this.disableSixthRow, 62 : this.minimumDayDate, 63 : this.maximumDayDate, 64 : super.key, 65 : }); 66 : 67 2 : @override 68 : Widget build(BuildContext context) { 69 2 : return Table( 70 2 : children: [ 71 2 : TableRow( 72 2 : children: List.generate( 73 : DateTime.daysPerWeek, 74 2 : (day) { 75 6 : final dayValue = this.daysOfWeek.entries.elementAt(day); 76 : 77 4 : return this.dayOfWeekBuilder( 78 2 : dayValue.value, 79 4 : dayValue.key.isWeekend, 80 : ); 81 : }, 82 : ), 83 : ), 84 2 : ...CalendarTableHelper.buildCalendarTableRow( 85 2 : calendarMonth: this.calendarMonth, 86 2 : disableSixthRow: this.disableSixthRow, 87 2 : selectedDateTime: this.selectedDateTime, 88 2 : dayBuilder: this.dayBuilder, 89 2 : onSelectDay: this.onSelectDay, 90 2 : disableClickOnOutOfRange: this.disableClickOnOutOfRange, 91 2 : minimumDayDate: this.minimumDayDate, 92 2 : maximumDayDate: this.maximumDayDate, 93 : ) 94 : ], 95 : ); 96 : } 97 : }