Skip to content

Commit 90f86c0

Browse files
Merge pull request #4 from Sasikumar3595/master
FLUT-4313-Sample updated with null safety.
2 parents 3c228d2 + 88e8afe commit 90f86c0

File tree

4 files changed

+68
-168
lines changed

4 files changed

+68
-168
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Row(
4141
highlightColor: Colors.lightGreen,
4242
onPressed: () {
4343
setState(() {
44-
_controller.backward();
44+
_controller.backward!();
4545
});
4646
},
4747
)),
@@ -64,7 +64,7 @@ Row(
6464
highlightColor: Colors.lightGreen,
6565
onPressed: () {
6666
setState(() {
67-
_controller.forward();
67+
_controller.forward!();
6868
});
6969
},
7070
)),
@@ -104,13 +104,13 @@ Using the `onViewChanged` callback of the date picker, you can get the mid date
104104

105105
```xml
106106
void viewChanged(DateRangePickerViewChangedArgs args) {
107-
_startDate = (args.visibleDateRange.startDate
108-
.difference(args.visibleDateRange.endDate)
109-
.inDays);
110-
var middleDate = (_startDate ~/ 2).toInt();
111-
midDate = args.visibleDateRange.startDate.add(Duration(days: middleDate));
107+
final DateTime visibleStartDate = args.visibleDateRange.startDate!;
108+
final DateTime visibleEndDate = args.visibleDateRange.endDate!;
109+
final int totalVisibleDays = (visibleStartDate.difference(visibleEndDate).inDays);
110+
final DateTime midDate =
111+
visibleStartDate.add(Duration(days: totalVisibleDays ~/ 2));
112112
headerString = DateFormat('MMMM yyyy').format(midDate).toString();
113-
SchedulerBinding.instance.addPostFrameCallback((duration) {
113+
SchedulerBinding.instance!.addPostFrameCallback((duration) {
114114
setState(() {});
115115
});
116116
}

lib/main.dart

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,17 @@ class HeaderCustomization extends StatefulWidget {
2323
}
2424

2525
class _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

Comments
 (0)