@@ -11,15 +11,10 @@ class MultipleResource extends StatefulWidget {
1111class MultipleResourceState extends State <MultipleResource > {
1212 bool _isJoseph = false ;
1313 bool _isStephen = false ;
14- List <Appointment > _appointments;
15- DataSource _dataSource;
16- List <Appointment > _josephAppointments, _stephenAppointments;
17-
18- @override
19- void initState () {
20- _dataSource = _getCalendarDataSource ();
21- super .initState ();
22- }
14+ final List <Appointment > _appointments = < Appointment > [];
15+ final DataSource _dataSource= DataSource (< Appointment > []);
16+ final List <Appointment > _josephAppointments= < Appointment > [];
17+ final List <Appointment > _stephenAppointments= < Appointment > [];
2318
2419 @override
2520 Widget build (BuildContext context) {
@@ -28,82 +23,76 @@ class MultipleResourceState extends State<MultipleResource> {
2823 debugShowCheckedModeBanner: false ,
2924 home: Scaffold (
3025 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 (
6326 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,
27+ SafeArea (
28+ child: Row (
29+ children: < Widget > [
30+ Switch (
31+ value: _isJoseph,
32+ onChanged: (value) {
33+ setState (() {
34+ if (value) {
35+ _updateJosephAppointments ();
36+ _dataSource.appointments! .addAll (_josephAppointments);
37+ _dataSource.notifyListeners (
38+ CalendarDataSourceAction .reset, _josephAppointments);
39+ } else {
40+ for (int i = 0 ; i < _josephAppointments.length; i++ ) {
41+ _dataSource.appointments! .remove (_josephAppointments[i]);
42+ }
43+ _josephAppointments.clear ();
44+ _dataSource.notifyListeners (
45+ CalendarDataSourceAction .reset, _josephAppointments);
46+ }
47+ _isJoseph = value;
48+ });
49+ },
50+ activeTrackColor: Colors .lightGreenAccent,
51+ activeColor: Colors .green,
52+ ),
53+ Text ('Dr.Joseph (Nephrologist)' ),
54+ ],
55+ ),
56+ ),
57+ Row (
58+ children: < Widget > [
59+ Switch (
60+ value: _isStephen,
61+ onChanged: (value) {
62+ setState (() {
63+ if (value) {
64+ _updateStephenAppointments ();
65+ _dataSource.appointments! .addAll (_stephenAppointments);
66+ _dataSource.notifyListeners (
67+ CalendarDataSourceAction .reset, _stephenAppointments);
68+ } else {
69+ for (int i = 0 ; i < _stephenAppointments.length; i++ ) {
70+ _dataSource.appointments! .remove (_stephenAppointments[i]);
71+ }
72+ _stephenAppointments.clear ();
73+ _dataSource.notifyListeners (
74+ CalendarDataSourceAction .reset, _stephenAppointments);
75+ }
76+ _isStephen = value;
77+ });
78+ },
79+ activeTrackColor: Colors .lightBlue,
80+ activeColor: Colors .blue,
81+ ),
82+ Text ('Dr.Stephen (Cardiologist)' ),
83+ ],
8684 ),
87- Text ('Dr.Stephen (Cardiologist)' ),
85+ Expanded (
86+ child: SfCalendar (
87+ view: CalendarView .week,
88+ dataSource: _dataSource,
89+ ))
8890 ],
89- ),
90- Expanded (
91- child: SfCalendar (
92- view: CalendarView .week,
93- dataSource: _dataSource,
94- ))
95- ],
96- )),
91+ )),
9792 );
9893 }
9994
100- DataSource _getCalendarDataSource () {
101- _appointments = < Appointment > [];
102- return DataSource (_appointments);
103- }
104-
10595 void _updateJosephAppointments () {
106- _josephAppointments = _josephAppointments ?? < Appointment > [];
10796 Appointment newAppointment = Appointment (
10897 startTime: DateTime .now (),
10998 endTime: DateTime .now ().add (Duration (hours: 1 )),
@@ -114,7 +103,7 @@ class MultipleResourceState extends State<MultipleResource> {
114103 startTime: DateTime .now ().add (Duration (days: - 3 , hours: 6 )),
115104 endTime: DateTime .now ().add (Duration (days: - 3 , hours: 7 )),
116105 subject:
117- 'Billion Hearts Beating brings you Happy Heart Fest to celebrate World Heart Day' ,
106+ 'Billion Hearts Beating brings you Happy Heart Fest to celebrate World Heart Day' ,
118107 color: Colors .lightGreen,
119108 );
120109 Appointment newAppointment2 = Appointment (
@@ -143,7 +132,6 @@ class MultipleResourceState extends State<MultipleResource> {
143132 }
144133
145134 void _updateStephenAppointments () {
146- _stephenAppointments = _stephenAppointments ?? < Appointment > [];
147135 Appointment newAppointment5 = Appointment (
148136 startTime: DateTime .now (),
149137 endTime: DateTime .now ().add (Duration (hours: 1 )),
0 commit comments