@@ -23,18 +23,19 @@ class CalendarPickerIntegration extends StatefulWidget {
2323}
2424
2525class CalendarPickerIntegrationState extends State <CalendarPickerIntegration > {
26- CalendarController _calendarController;
27- DateRangePickerController _dateRangePickerController;
28- List < Appointment > _appointments ;
29- List < DateTime > _appointmentDates ;
30- List <DateTime > _appointmentDatesCollection ;
26+ final CalendarController _calendarController = CalendarController () ;
27+ final DateRangePickerController _dateRangePickerController =
28+ DateRangePickerController () ;
29+ late _AppointmentDataSource _appointmentDataSource ;
30+ late List <DateTime > _specialDates ;
3131
3232 @override
3333 void initState () {
34- _calendarController = CalendarController ();
35- _dateRangePickerController = DateRangePickerController ();
36- _appointmentDates = < DateTime > [];
37- _appointmentDatesCollection= < DateTime > [];
34+ _appointmentDataSource = _getCalendarDataSource ();
35+ _specialDates = < DateTime > [];
36+ for (int i = 0 ; i < _appointmentDataSource.appointments! .length; i++ ) {
37+ _specialDates.add (_appointmentDataSource.appointments! [i].startTime);
38+ }
3839 super .initState ();
3940 }
4041
@@ -55,7 +56,7 @@ class CalendarPickerIntegrationState extends State<CalendarPickerIntegration> {
5556 controller: _dateRangePickerController,
5657 monthViewSettings: DateRangePickerMonthViewSettings (
5758 numberOfWeeksInView: 1 ,
58- specialDates: _appointmentDatesCollection ,
59+ specialDates: _specialDates ,
5960 ),
6061 onSelectionChanged: selectionChanged,
6162 monthCellStyle: DateRangePickerMonthCellStyle (
@@ -82,7 +83,7 @@ class CalendarPickerIntegrationState extends State<CalendarPickerIntegration> {
8283 headerHeight: 0 ,
8384 controller: _calendarController,
8485 viewHeaderHeight: 0 ,
85- dataSource: _getCalendarDataSource () ,
86+ dataSource: _appointmentDataSource ,
8687 onViewChanged: viewChanged,
8788 ),
8889 ),
@@ -93,61 +94,52 @@ class CalendarPickerIntegrationState extends State<CalendarPickerIntegration> {
9394 }
9495
9596 void selectionChanged (DateRangePickerSelectionChangedArgs args) {
96- SchedulerBinding .instance.addPostFrameCallback ((timeStamp) {
97+ SchedulerBinding .instance! .addPostFrameCallback ((timeStamp) {
9798 _calendarController.displayDate = args.value;
9899 });
99100 }
100101
101102 _AppointmentDataSource _getCalendarDataSource () {
102- _appointments = < Appointment > [];
103-
104- _appointments.add (Appointment (
103+ final List <Appointment > appointments = < Appointment > [];
104+ appointments.add (Appointment (
105105 startTime: DateTime .now ().add (Duration (days: 2 )),
106106 endTime: DateTime .now ().add (Duration (days: 2 , hours: 1 )),
107107 subject: 'Planning' ,
108108 color: Colors .red,
109109 ));
110- _appointments .add (Appointment (
110+ appointments .add (Appointment (
111111 startTime: DateTime .now ().add (Duration (days: 3 )),
112112 endTime: DateTime .now ().add (Duration (days: 3 , hours: 1 )),
113113 subject: 'Meeting' ,
114114 color: Colors .blue,
115115 ));
116- return _AppointmentDataSource (_appointments );
116+ return _AppointmentDataSource (appointments );
117117 }
118118
119119 void viewChanged (ViewChangedDetails viewChangedDetails) {
120- DateTime _specialDate;
121- for (int i = 0 ; i <= viewChangedDetails.visibleDates.length; i++ ) {
122- _specialDate = _appointments[i].startTime;
123- _appointmentDates.add (_specialDate);
124- }
125- SchedulerBinding .instance.addPostFrameCallback ((timeStamp) {
120+ SchedulerBinding .instance! .addPostFrameCallback ((timeStamp) {
126121 _dateRangePickerController.selectedDate =
127122 viewChangedDetails.visibleDates[0 ];
128123 _dateRangePickerController.displayDate =
129124 viewChangedDetails.visibleDates[0 ];
130- setState (() {
131- _appointmentDatesCollection = _appointmentDates;
132- });
133125 });
134126 }
135127}
136128
137129class _MonthCellDecoration extends Decoration {
138130 const _MonthCellDecoration (
139131 {this .borderColor,
140- this .backgroundColor,
141- this .showIndicator,
142- this .indicatorColor});
132+ required this .backgroundColor,
133+ required this .showIndicator,
134+ required this .indicatorColor});
143135
144- final Color borderColor;
136+ final Color ? borderColor;
145137 final Color backgroundColor;
146138 final bool showIndicator;
147139 final Color indicatorColor;
148140
149141 @override
150- BoxPainter createBoxPainter ([VoidCallback onChanged]) {
142+ BoxPainter createBoxPainter ([VoidCallback ? onChanged]) {
151143 return _MonthCellDecorationPainter (
152144 borderColor: borderColor,
153145 backgroundColor: backgroundColor,
@@ -159,18 +151,18 @@ class _MonthCellDecoration extends Decoration {
159151class _MonthCellDecorationPainter extends BoxPainter {
160152 _MonthCellDecorationPainter (
161153 {this .borderColor,
162- this .backgroundColor,
163- this .showIndicator,
164- this .indicatorColor});
154+ required this .backgroundColor,
155+ required this .showIndicator,
156+ required this .indicatorColor});
165157
166- final Color borderColor;
158+ final Color ? borderColor;
167159 final Color backgroundColor;
168160 final bool showIndicator;
169161 final Color indicatorColor;
170162
171163 @override
172164 void paint (Canvas canvas, Offset offset, ImageConfiguration configuration) {
173- final Rect bounds = offset & configuration.size;
165+ final Rect bounds = offset & configuration.size! ;
174166 _drawDecoration (canvas, bounds);
175167 }
176168
@@ -181,7 +173,7 @@ class _MonthCellDecorationPainter extends BoxPainter {
181173 paint.style = PaintingStyle .stroke;
182174 paint.strokeWidth = 1 ;
183175 if (borderColor != null ) {
184- paint.color = borderColor;
176+ paint.color = borderColor! ;
185177 canvas.drawRRect (
186178 RRect .fromRectAndRadius (bounds, const Radius .circular (5 )), paint);
187179 }
0 commit comments