Skip to content

Commit 8c20e33

Browse files
committed
FLUT-4313-Sample updated with null safety.
1 parent 9c89263 commit 8c20e33

File tree

3 files changed

+104
-114
lines changed

3 files changed

+104
-114
lines changed

lib/main.dart

Lines changed: 78 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,10 @@ class HeaderCustomization extends StatefulWidget {
2424

2525
class HeaderCustomizationState extends State<HeaderCustomization> {
2626
final List<String> _days = <String>['S', 'M', 'T', 'W', 'T', 'F', 'S'];
27-
DateRangePickerController _controller;
28-
String _headerString;
29-
PickerDateRange _visibleDateRange;
30-
int _selectedWeekDay;
31-
32-
@override
33-
void initState() {
34-
_controller = DateRangePickerController();
35-
_headerString = '';
36-
_selectedWeekDay = -1;
37-
super.initState();
38-
}
27+
final DateRangePickerController _controller = DateRangePickerController();
28+
String _headerString = '';
29+
late PickerDateRange _visibleDateRange;
30+
int _selectedWeekDay = -1;
3931

4032
@override
4133
Widget build(BuildContext context) {
@@ -45,90 +37,89 @@ class HeaderCustomizationState extends State<HeaderCustomization> {
4537

4638
return Scaffold(
4739
body: Column(
48-
mainAxisAlignment: MainAxisAlignment.center,
40+
mainAxisAlignment: MainAxisAlignment.center,
41+
children: <Widget>[
42+
Container(
43+
child: Row(
4944
children: <Widget>[
5045
Container(
51-
child: Row(
52-
children: <Widget>[
53-
Container(
54-
margin: const EdgeInsets.symmetric(horizontal: 4),
55-
width: viewHeaderCellWidth,
56-
child: IconButton(
57-
icon: Icon(Icons.arrow_left),
58-
color: Colors.black,
59-
onPressed: () {
60-
setState(() {
61-
_controller.backward();
62-
});
63-
},
64-
)),
65-
Expanded(
66-
child: Text(_headerString,
67-
textAlign: TextAlign.center,
68-
style: TextStyle(fontSize: 25, color: Colors.black)),
69-
),
70-
Container(
71-
margin: const EdgeInsets.symmetric(horizontal: 4),
72-
width: viewHeaderCellWidth,
73-
child: IconButton(
74-
icon: Icon(Icons.arrow_right),
75-
color: Colors.black,
76-
onPressed: () {
77-
setState(() {
78-
_controller.forward();
79-
});
80-
},
81-
)),
82-
],
46+
margin: const EdgeInsets.symmetric(horizontal: 4),
47+
width: viewHeaderCellWidth,
48+
child: IconButton(
49+
icon: Icon(Icons.arrow_left),
50+
color: Colors.black,
51+
onPressed: () {
52+
setState(() {
53+
_controller.backward!();
54+
});
55+
},
8356
)),
57+
Expanded(
58+
child: Text(_headerString,
59+
textAlign: TextAlign.center,
60+
style: TextStyle(fontSize: 25, color: Colors.black)),
61+
),
8462
Container(
85-
height: viewHeaderHeight,
86-
width: width,
8763
margin: const EdgeInsets.symmetric(horizontal: 4),
88-
child: ListView.builder(
89-
itemCount: _days.length,
90-
scrollDirection: Axis.horizontal,
91-
itemBuilder: (BuildContext context, int index) {
92-
return GestureDetector(
93-
onTap: ()
94-
{
95-
final int selectedIndex = index == 0 ? 7 : index;
96-
_selectedWeekDay = selectedIndex;
97-
_updateSelectedDates();
98-
},
99-
child: Container(
100-
alignment: Alignment.center,
101-
width: viewHeaderCellWidth,
102-
height: viewHeaderHeight,
103-
child: Text(_days[index]),
104-
));
105-
})),
106-
Container(
107-
margin: const EdgeInsets.symmetric(horizontal: 4),
108-
child: SfDateRangePicker(
109-
selectionMode: DateRangePickerSelectionMode.multiple,
110-
controller: _controller,
111-
headerHeight: 0,
112-
onViewChanged: viewChanged,
113-
monthViewSettings:
114-
DateRangePickerMonthViewSettings(viewHeaderHeight: 0),
115-
),
116-
)
64+
width: viewHeaderCellWidth,
65+
child: IconButton(
66+
icon: Icon(Icons.arrow_right),
67+
color: Colors.black,
68+
onPressed: () {
69+
setState(() {
70+
_controller.forward!();
71+
});
72+
},
73+
)),
11774
],
118-
));
75+
)),
76+
Container(
77+
height: viewHeaderHeight,
78+
width: width,
79+
margin: const EdgeInsets.symmetric(horizontal: 4),
80+
child: ListView.builder(
81+
itemCount: _days.length,
82+
scrollDirection: Axis.horizontal,
83+
itemBuilder: (BuildContext context, int index) {
84+
return GestureDetector(
85+
onTap: () {
86+
final int selectedIndex = index == 0 ? 7 : index;
87+
_selectedWeekDay = selectedIndex;
88+
_updateSelectedDates();
89+
},
90+
child: Container(
91+
alignment: Alignment.center,
92+
width: viewHeaderCellWidth,
93+
height: viewHeaderHeight,
94+
child: Text(_days[index]),
95+
));
96+
})),
97+
Container(
98+
margin: const EdgeInsets.symmetric(horizontal: 4),
99+
child: SfDateRangePicker(
100+
selectionMode: DateRangePickerSelectionMode.multiple,
101+
controller: _controller,
102+
headerHeight: 0,
103+
onViewChanged: viewChanged,
104+
monthViewSettings:
105+
DateRangePickerMonthViewSettings(viewHeaderHeight: 0),
106+
),
107+
)
108+
],
109+
));
119110
}
120111

121112
void _updateSelectedDates() {
122-
if (_selectedWeekDay == -1 || _visibleDateRange == null) {
113+
if (_selectedWeekDay == -1) {
123114
return;
124115
}
125116

126117
final List<DateTime> selectedDates = <DateTime>[];
127-
DateTime date = _visibleDateRange.startDate;
128-
while (date.isBefore(_visibleDateRange.endDate) ||
129-
(date.year == _visibleDateRange.endDate.year &&
130-
date.month == _visibleDateRange.endDate.month &&
131-
date.day == _visibleDateRange.endDate.day)) {
118+
DateTime date = _visibleDateRange.startDate!;
119+
while (date.isBefore(_visibleDateRange.endDate!) ||
120+
(date.year == _visibleDateRange.endDate!.year &&
121+
date.month == _visibleDateRange.endDate!.month &&
122+
date.day == _visibleDateRange.endDate!.day)) {
132123
if (_selectedWeekDay == date.weekday) {
133124
selectedDates.add(date);
134125
}
@@ -141,14 +132,13 @@ class HeaderCustomizationState extends State<HeaderCustomization> {
141132

142133
void viewChanged(DateRangePickerViewChangedArgs args) {
143134
_visibleDateRange = args.visibleDateRange;
144-
final int daysCount = (args.visibleDateRange.endDate
145-
.difference(args.visibleDateRange.startDate)
135+
final int daysCount = (args.visibleDateRange.endDate!
136+
.difference(args.visibleDateRange.startDate!)
146137
.inDays);
147-
var middleDate = (daysCount ~/ 2).toInt();
148138
final DateTime date =
149-
args.visibleDateRange.startDate.add(Duration(days: middleDate));
139+
args.visibleDateRange.startDate!.add(Duration(days: daysCount ~/ 2));
150140
_headerString = DateFormat('MMMM yyyy').format(date).toString();
151-
SchedulerBinding.instance.addPostFrameCallback((duration) {
141+
SchedulerBinding.instance!.addPostFrameCallback((duration) {
152142
setState(() {});
153143
});
154144
}

pubspec.lock

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,42 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.5.0-nullsafety.3"
10+
version: "2.5.0"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
1414
name: boolean_selector
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "2.1.0-nullsafety.3"
17+
version: "2.1.0"
1818
characters:
1919
dependency: transitive
2020
description:
2121
name: characters
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.1.0-nullsafety.5"
24+
version: "1.1.0"
2525
charcode:
2626
dependency: transitive
2727
description:
2828
name: charcode
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "1.2.0-nullsafety.3"
31+
version: "1.2.0"
3232
clock:
3333
dependency: transitive
3434
description:
3535
name: clock
3636
url: "https://pub.dartlang.org"
3737
source: hosted
38-
version: "1.1.0-nullsafety.3"
38+
version: "1.1.0"
3939
collection:
4040
dependency: transitive
4141
description:
4242
name: collection
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "1.15.0-nullsafety.5"
45+
version: "1.15.0"
4646
cupertino_icons:
4747
dependency: "direct main"
4848
description:
@@ -56,7 +56,7 @@ packages:
5656
name: fake_async
5757
url: "https://pub.dartlang.org"
5858
source: hosted
59-
version: "1.2.0-nullsafety.3"
59+
version: "1.2.0"
6060
flutter:
6161
dependency: "direct main"
6262
description: flutter
@@ -73,28 +73,28 @@ packages:
7373
name: intl
7474
url: "https://pub.dartlang.org"
7575
source: hosted
76-
version: "0.16.1"
76+
version: "0.17.0"
7777
matcher:
7878
dependency: transitive
7979
description:
8080
name: matcher
8181
url: "https://pub.dartlang.org"
8282
source: hosted
83-
version: "0.12.10-nullsafety.3"
83+
version: "0.12.10"
8484
meta:
8585
dependency: transitive
8686
description:
8787
name: meta
8888
url: "https://pub.dartlang.org"
8989
source: hosted
90-
version: "1.3.0-nullsafety.6"
90+
version: "1.3.0"
9191
path:
9292
dependency: transitive
9393
description:
9494
name: path
9595
url: "https://pub.dartlang.org"
9696
source: hosted
97-
version: "1.8.0-nullsafety.3"
97+
version: "1.8.0"
9898
sky_engine:
9999
dependency: transitive
100100
description: flutter
@@ -106,69 +106,69 @@ packages:
106106
name: source_span
107107
url: "https://pub.dartlang.org"
108108
source: hosted
109-
version: "1.8.0-nullsafety.4"
109+
version: "1.8.1"
110110
stack_trace:
111111
dependency: transitive
112112
description:
113113
name: stack_trace
114114
url: "https://pub.dartlang.org"
115115
source: hosted
116-
version: "1.10.0-nullsafety.6"
116+
version: "1.10.0"
117117
stream_channel:
118118
dependency: transitive
119119
description:
120120
name: stream_channel
121121
url: "https://pub.dartlang.org"
122122
source: hosted
123-
version: "2.1.0-nullsafety.3"
123+
version: "2.1.0"
124124
string_scanner:
125125
dependency: transitive
126126
description:
127127
name: string_scanner
128128
url: "https://pub.dartlang.org"
129129
source: hosted
130-
version: "1.1.0-nullsafety.3"
130+
version: "1.1.0"
131131
syncfusion_flutter_core:
132132
dependency: transitive
133133
description:
134134
name: syncfusion_flutter_core
135135
url: "https://pub.dartlang.org"
136136
source: hosted
137-
version: "18.4.41"
137+
version: "19.1.55"
138138
syncfusion_flutter_datepicker:
139139
dependency: "direct main"
140140
description:
141141
name: syncfusion_flutter_datepicker
142142
url: "https://pub.dartlang.org"
143143
source: hosted
144-
version: "18.4.41-beta"
144+
version: "19.1.55-beta"
145145
term_glyph:
146146
dependency: transitive
147147
description:
148148
name: term_glyph
149149
url: "https://pub.dartlang.org"
150150
source: hosted
151-
version: "1.2.0-nullsafety.3"
151+
version: "1.2.0"
152152
test_api:
153153
dependency: transitive
154154
description:
155155
name: test_api
156156
url: "https://pub.dartlang.org"
157157
source: hosted
158-
version: "0.2.19-nullsafety.6"
158+
version: "0.2.19"
159159
typed_data:
160160
dependency: transitive
161161
description:
162162
name: typed_data
163163
url: "https://pub.dartlang.org"
164164
source: hosted
165-
version: "1.3.0-nullsafety.5"
165+
version: "1.3.0"
166166
vector_math:
167167
dependency: transitive
168168
description:
169169
name: vector_math
170170
url: "https://pub.dartlang.org"
171171
source: hosted
172-
version: "2.1.0-nullsafety.5"
172+
version: "2.1.0"
173173
sdks:
174-
dart: ">=2.12.0-0.0 <3.0.0"
174+
dart: ">=2.12.0 <3.0.0"

pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1818
version: 1.0.0+1
1919

2020
environment:
21-
sdk: ">=2.7.0 <3.0.0"
21+
sdk: '>=2.12.0 <3.0.0'
2222

2323
dependencies:
2424
flutter:
2525
sdk: flutter
2626
# syncfusion_flutter_calendar:
2727
# path: E:\jan 20\flutter-calendar\flutter_calendar\syncfusion_flutter_calendar
28-
syncfusion_flutter_datepicker: 18.4.41-beta
29-
intl: ^0.16.1
28+
syncfusion_flutter_datepicker: ^19.1.55-beta
29+
intl: ^0.17.0
3030

3131
# The following adds the Cupertino Icons font to your application.
3232
# Use with the CupertinoIcons class for iOS style icons.
33-
cupertino_icons: ^1.0.1
33+
cupertino_icons: ^1.0.2
3434

3535
dev_dependencies:
3636
flutter_test:

0 commit comments

Comments
 (0)