@@ -23,36 +23,17 @@ class HeaderCustomization extends StatefulWidget {
2323}
2424
2525class _HeaderCustomizationState extends State <HeaderCustomization > {
26- DateRangePickerController _controller;
27- int _startDate;
28- String headerString;
29- DateTime midDate;
30- double width, cellWidth, height, cellHeight;
31-
32- @override
33- void initState () {
34- // TODO: implement initState
35- _controller = DateRangePickerController ();
36- _startDate = 0 ;
37- width = 0.0 ;
38- cellWidth = 0.0 ;
39- height = 0.0 ;
40- cellHeight = 0.0 ;
41- midDate = DateTime .now ();
42- headerString = '' ;
43- super .initState ();
44- }
26+ final DateRangePickerController _controller = DateRangePickerController ();
27+ String headerString = '' ;
4528
4629 @override
4730 Widget build (BuildContext context) {
48- width = MediaQuery .of (context).size.width;
49- cellWidth = width / 9 ;
50- height = MediaQuery .of (context).size.height;
51- cellHeight = height / 17 ;
31+ final double width = MediaQuery .of (context).size.width;
32+ final double cellWidth = width / 9 ;
5233
5334 return Scaffold (
5435 body: Column (
55- mainAxisAlignment: MainAxisAlignment .center,
36+ mainAxisAlignment: MainAxisAlignment .center,
5637 children: < Widget > [
5738 Row (
5839 children: < Widget > [
@@ -71,7 +52,7 @@ class _HeaderCustomizationState extends State<HeaderCustomization> {
7152 highlightColor: Colors .lightGreen,
7253 onPressed: () {
7354 setState (() {
74- _controller.backward ();
55+ _controller.backward ! ();
7556 });
7657 },
7758 )),
@@ -94,7 +75,7 @@ class _HeaderCustomizationState extends State<HeaderCustomization> {
9475 highlightColor: Colors .lightGreen,
9576 onPressed: () {
9677 setState (() {
97- _controller.forward ();
78+ _controller.forward ! ();
9879 });
9980 },
10081 )),
@@ -118,22 +99,23 @@ class _HeaderCustomizationState extends State<HeaderCustomization> {
11899 monthCellStyle: DateRangePickerMonthCellStyle (
119100 cellDecoration: BoxDecoration (color: Color (0xFF6fb98f )),
120101 leadingDatesDecoration:
121- BoxDecoration (color: Color (0xFF6fb98f )),
102+ BoxDecoration (color: Color (0xFF6fb98f )),
122103 trailingDatesDecoration:
123- BoxDecoration (color: Color (0xFF6fb98f )))),
104+ BoxDecoration (color: Color (0xFF6fb98f )))),
124105 )
125106 ],
126107 ));
127108 }
128109
129110 void viewChanged (DateRangePickerViewChangedArgs args) {
130- _startDate = (args.visibleDateRange.startDate
131- .difference (args.visibleDateRange.endDate)
132- .inDays);
133- var middleDate = (_startDate ~ / 2 ).toInt ();
134- midDate = args.visibleDateRange.startDate.add (Duration (days: middleDate));
111+ final DateTime visibleStartDate = args.visibleDateRange.startDate! ;
112+ final DateTime visibleEndDate = args.visibleDateRange.endDate! ;
113+ final int totalVisibleDays =
114+ (visibleStartDate.difference (visibleEndDate).inDays);
115+ final DateTime midDate =
116+ visibleStartDate.add (Duration (days: totalVisibleDays ~ / 2 ));
135117 headerString = DateFormat ('MMMM yyyy' ).format (midDate).toString ();
136- SchedulerBinding .instance.addPostFrameCallback ((duration) {
118+ SchedulerBinding .instance! .addPostFrameCallback ((duration) {
137119 setState (() {});
138120 });
139121 }
0 commit comments