Skip to content

Commit fdbdd52

Browse files
Update main.dart
Sample updated to null safety.
1 parent a919226 commit fdbdd52

File tree

1 file changed

+78
-78
lines changed

1 file changed

+78
-78
lines changed

lib/main.dart

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class MultipleResource extends StatefulWidget {
1111
class MultipleResourceState extends State<MultipleResource> {
1212
bool _isJoseph = false;
1313
bool _isStephen = false;
14-
List<Appointment> _appointments;
15-
DataSource _dataSource;
16-
List<Appointment> _josephAppointments, _stephenAppointments;
14+
List<Appointment>? _appointments;
15+
DataSource? _dataSource;
16+
List<Appointment>? _josephAppointments, _stephenAppointments;
1717

1818
@override
1919
void initState() {
@@ -28,78 +28,78 @@ class MultipleResourceState extends State<MultipleResource> {
2828
debugShowCheckedModeBanner: false,
2929
home: Scaffold(
3030
body: Column(
31-
children: <Widget>[
32-
SafeArea(
33-
child: Row(
34-
children: <Widget>[
35-
Switch(
36-
value: _isJoseph,
37-
onChanged: (value) {
38-
setState(() {
39-
if (value) {
40-
_updateJosephAppointments();
41-
_dataSource.appointments.addAll(_josephAppointments);
42-
_dataSource.notifyListeners(
43-
CalendarDataSourceAction.reset, _josephAppointments);
44-
} else {
45-
for (int i = 0; i < _josephAppointments.length; i++) {
46-
_dataSource.appointments.remove(_josephAppointments[i]);
47-
}
48-
_josephAppointments.clear();
49-
_dataSource.notifyListeners(
50-
CalendarDataSourceAction.reset, _josephAppointments);
51-
}
52-
_isJoseph = value;
53-
});
54-
},
55-
activeTrackColor: Colors.lightGreenAccent,
56-
activeColor: Colors.green,
57-
),
58-
Text('Dr.Joseph (Nephrologist)'),
59-
],
60-
),
61-
),
62-
Row(
6331
children: <Widget>[
64-
Switch(
65-
value: _isStephen,
66-
onChanged: (value) {
67-
setState(() {
68-
if (value) {
69-
_updateStephenAppointments();
70-
_dataSource.appointments.addAll(_stephenAppointments);
71-
_dataSource.notifyListeners(
72-
CalendarDataSourceAction.reset, _stephenAppointments);
73-
} else {
74-
for (int i = 0; i < _stephenAppointments.length; i++) {
75-
_dataSource.appointments.remove(_stephenAppointments[i]);
76-
}
77-
_stephenAppointments.clear();
78-
_dataSource.notifyListeners(
79-
CalendarDataSourceAction.reset, _stephenAppointments);
80-
}
81-
_isStephen = value;
82-
});
83-
},
84-
activeTrackColor: Colors.lightBlue,
85-
activeColor: Colors.blue,
32+
SafeArea(
33+
child: Row(
34+
children: <Widget>[
35+
Switch(
36+
value: _isJoseph,
37+
onChanged: (value) {
38+
setState(() {
39+
if (value) {
40+
_updateJosephAppointments();
41+
_dataSource!.appointments!.addAll(_josephAppointments!);
42+
_dataSource!.notifyListeners(
43+
CalendarDataSourceAction.reset, _josephAppointments!);
44+
} else {
45+
for (int i = 0; i < _josephAppointments!.length; i++) {
46+
_dataSource!.appointments!.remove(_josephAppointments![i]);
47+
}
48+
_josephAppointments!.clear();
49+
_dataSource!.notifyListeners(
50+
CalendarDataSourceAction.reset, _josephAppointments!);
51+
}
52+
_isJoseph = value;
53+
});
54+
},
55+
activeTrackColor: Colors.lightGreenAccent,
56+
activeColor: Colors.green,
57+
),
58+
Text('Dr.Joseph (Nephrologist)'),
59+
],
60+
),
61+
),
62+
Row(
63+
children: <Widget>[
64+
Switch(
65+
value: _isStephen,
66+
onChanged: (value) {
67+
setState(() {
68+
if (value) {
69+
_updateStephenAppointments();
70+
_dataSource!.appointments!.addAll(_stephenAppointments!);
71+
_dataSource!.notifyListeners(
72+
CalendarDataSourceAction.reset, _stephenAppointments!);
73+
} else {
74+
for (int i = 0; i < _stephenAppointments!.length; i++) {
75+
_dataSource!.appointments!.remove(_stephenAppointments![i]);
76+
}
77+
_stephenAppointments!.clear();
78+
_dataSource!.notifyListeners(
79+
CalendarDataSourceAction.reset, _stephenAppointments!);
80+
}
81+
_isStephen = value;
82+
});
83+
},
84+
activeTrackColor: Colors.lightBlue,
85+
activeColor: Colors.blue,
86+
),
87+
Text('Dr.Stephen (Cardiologist)'),
88+
],
8689
),
87-
Text('Dr.Stephen (Cardiologist)'),
90+
Expanded(
91+
child: SfCalendar(
92+
view: CalendarView.week,
93+
dataSource: _dataSource,
94+
))
8895
],
89-
),
90-
Expanded(
91-
child: SfCalendar(
92-
view: CalendarView.week,
93-
dataSource: _dataSource,
94-
))
95-
],
96-
)),
96+
)),
9797
);
9898
}
9999

100100
DataSource _getCalendarDataSource() {
101101
_appointments = <Appointment>[];
102-
return DataSource(_appointments);
102+
return DataSource(_appointments!);
103103
}
104104

105105
void _updateJosephAppointments() {
@@ -114,7 +114,7 @@ class MultipleResourceState extends State<MultipleResource> {
114114
startTime: DateTime.now().add(Duration(days: -3, hours: 6)),
115115
endTime: DateTime.now().add(Duration(days: -3, hours: 7)),
116116
subject:
117-
'Billion Hearts Beating brings you Happy Heart Fest to celebrate World Heart Day',
117+
'Billion Hearts Beating brings you Happy Heart Fest to celebrate World Heart Day',
118118
color: Colors.lightGreen,
119119
);
120120
Appointment newAppointment2 = Appointment(
@@ -135,11 +135,11 @@ class MultipleResourceState extends State<MultipleResource> {
135135
subject: 'World Continence Week - Free Check-up Camp for women',
136136
color: Colors.lightGreen,
137137
);
138-
_josephAppointments.add(newAppointment);
139-
_josephAppointments.add(newAppointment1);
140-
_josephAppointments.add(newAppointment2);
141-
_josephAppointments.add(newAppointment3);
142-
_josephAppointments.add(newAppointment4);
138+
_josephAppointments!.add(newAppointment);
139+
_josephAppointments!.add(newAppointment1);
140+
_josephAppointments!.add(newAppointment2);
141+
_josephAppointments!.add(newAppointment3);
142+
_josephAppointments!.add(newAppointment4);
143143
}
144144

145145
void _updateStephenAppointments() {
@@ -174,11 +174,11 @@ class MultipleResourceState extends State<MultipleResource> {
174174
subject: 'World Ostomy Day and Awareness Program',
175175
color: Colors.lightBlue,
176176
);
177-
_stephenAppointments.add(newAppointment5);
178-
_stephenAppointments.add(newAppointment6);
179-
_stephenAppointments.add(newAppointment7);
180-
_stephenAppointments.add(newAppointment8);
181-
_stephenAppointments.add(newAppointment9);
177+
_stephenAppointments!.add(newAppointment5);
178+
_stephenAppointments!.add(newAppointment6);
179+
_stephenAppointments!.add(newAppointment7);
180+
_stephenAppointments!.add(newAppointment8);
181+
_stephenAppointments!.add(newAppointment9);
182182
}
183183
}
184184

0 commit comments

Comments
 (0)