Skip to content

Commit 6a9574c

Browse files
authored
Merge pull request #3 from Indumathi1195R/patch-2
Update main.dart
2 parents 75aa2ab + d52979e commit 6a9574c

File tree

2 files changed

+78
-55
lines changed

2 files changed

+78
-55
lines changed

lib/main.dart

Lines changed: 71 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @dart=2.9
12
import 'dart:collection';
23
import 'dart:math';
34

@@ -13,6 +14,7 @@ class LoadDataFromFireBase extends StatelessWidget {
1314
@override
1415
Widget build(BuildContext context) {
1516
return MaterialApp(
17+
debugShowCheckedModeBanner: false,
1618
title: 'FireBase',
1719
home: LoadDataFromFireStore(),
1820
);
@@ -28,6 +30,7 @@ class LoadDataFromFireStoreState extends State<LoadDataFromFireStore> {
2830
DataSnapshot querySnapshot;
2931
dynamic data;
3032
List<Color> _colorCollection;
33+
final List<String> options = <String>['Add', 'Delete'];
3134

3235
@override
3336
void initState() {
@@ -45,7 +48,38 @@ class LoadDataFromFireStoreState extends State<LoadDataFromFireStore> {
4548
@override
4649
Widget build(BuildContext context) {
4750
return Scaffold(
48-
51+
appBar: AppBar(
52+
leading: PopupMenuButton<String>(
53+
icon: Icon(Icons.settings),
54+
itemBuilder: (BuildContext context) => options.map((String choice) {
55+
return PopupMenuItem<String>(
56+
value: choice,
57+
child: Text(choice),
58+
);
59+
}).toList(),
60+
onSelected: (String value) {
61+
if (value == 'Add') {
62+
final dbRef =
63+
FirebaseDatabase.instance.reference().child("CalendarData");
64+
dbRef.push().set({
65+
"StartTime": '07/04/2020 07:00:00',
66+
"EndTime": '07/04/2020 08:00:00',
67+
"Subject": 'NewMeeting',
68+
"ResourceId": '0001'
69+
}).then((_) {
70+
Scaffold.of(context).showSnackBar(
71+
SnackBar(content: Text('Successfully Added')));
72+
}).catchError((onError) {
73+
print(onError);
74+
});
75+
} else if (value == 'Delete') {
76+
final dbRef =
77+
FirebaseDatabase.instance.reference().child("CalendarData");
78+
dbRef.remove();
79+
}
80+
},
81+
),
82+
),
4983
body: _showCalendar(),
5084
);
5185
}
@@ -66,45 +100,27 @@ class LoadDataFromFireStoreState extends State<LoadDataFromFireStore> {
66100
isAllDay: false,
67101
from: DateFormat('dd/MM/yyyy HH:mm:ss').parse(data['StartTime']),
68102
to: DateFormat('dd/MM/yyyy HH:mm:ss').parse(data['EndTime']),
69-
background: _colorCollection[random.nextInt(9)]));
103+
background: _colorCollection[random.nextInt(9)],
104+
resourceId: data['ResourceId']));
70105
}
71106
} else {
72107
return Center(
73108
child: CircularProgressIndicator(),
74109
);
75110
}
76111

77-
return SafeArea(
78-
child: Column(
79-
children: [
80-
Container(
81-
height: 400,
82-
child: SfCalendar(
83-
view: CalendarView.month,
84-
initialDisplayDate: DateTime(2020, 4, 5, 9, 0, 0),
85-
dataSource: _getCalendarDataSource(collection),
86-
monthViewSettings: MonthViewSettings(showAgenda: true),
87-
),
88-
),
89-
RaisedButton(onPressed: () {
90-
final dbRef = FirebaseDatabase.instance.reference().child("CalendarData");
91-
dbRef.push().set({
92-
"StartTime": '07/04/2020 07:00:00',
93-
"EndTime": '07/04/2020 08:00:00',
94-
"Subject":'NewMeeting',
95-
}).then((_) {
96-
Scaffold.of(context).showSnackBar(
97-
SnackBar(content: Text('Successfully Added')));
98-
}).catchError((onError) {
99-
print(onError);
100-
});
101-
}, child: Text("Add")),
102-
RaisedButton(onPressed: () {
103-
final dbRef = FirebaseDatabase.instance.reference().child("CalendarData");
104-
dbRef.remove();
105-
}, child: Text("Delete")),
106-
],
107-
));
112+
return SfCalendar(
113+
view: CalendarView.timelineDay,
114+
allowedViews: [
115+
CalendarView.timelineDay,
116+
CalendarView.timelineWeek,
117+
CalendarView.timelineWorkWeek,
118+
CalendarView.timelineMonth,
119+
],
120+
initialDisplayDate: DateTime(2020, 4, 5, 9, 0, 0),
121+
dataSource: _getCalendarDataSource(collection),
122+
monthViewSettings: MonthViewSettings(showAgenda: true),
123+
);
108124
}
109125
}
110126

@@ -125,12 +141,19 @@ class LoadDataFromFireStoreState extends State<LoadDataFromFireStore> {
125141

126142
MeetingDataSource _getCalendarDataSource([List<Meeting> collection]) {
127143
List<Meeting> meetings = collection ?? <Meeting>[];
128-
return MeetingDataSource(meetings);
144+
List<CalendarResource> resourceColl = <CalendarResource>[];
145+
resourceColl.add(CalendarResource(
146+
displayName: 'John',
147+
id: '0001',
148+
color: Colors.red,
149+
));
150+
return MeetingDataSource(meetings, resourceColl);
129151
}
130152

131153
class MeetingDataSource extends CalendarDataSource {
132-
MeetingDataSource(List<Meeting> source) {
154+
MeetingDataSource(List<Meeting> source, List<CalendarResource> resourceColl) {
133155
appointments = source;
156+
resources = resourceColl;
134157
}
135158

136159
@override
@@ -157,6 +180,11 @@ class MeetingDataSource extends CalendarDataSource {
157180
Color getColor(int index) {
158181
return appointments[index].background;
159182
}
183+
184+
@override
185+
List<Object> getResourceIds(int index) {
186+
return [appointments[index].resourceId];
187+
}
160188
}
161189

162190
getDataFromDatabase() async {
@@ -166,11 +194,18 @@ getDataFromDatabase() async {
166194
}
167195

168196
class Meeting {
169-
Meeting({this.eventName, this.from, this.to, this.background, this.isAllDay});
197+
Meeting(
198+
{this.eventName,
199+
this.from,
200+
this.to,
201+
this.background,
202+
this.isAllDay,
203+
this.resourceId});
170204

171205
String eventName;
172206
DateTime from;
173207
DateTime to;
174208
Color background;
175209
bool isAllDay;
210+
String resourceId;
176211
}

pubspec.yaml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: flutter_firebase_calendar
22
description: A new Flutter application.
3-
43
# The following defines the version and build number for your application.
54
# A version number is three numbers separated by dots, like 1.2.43
65
# followed by an optional build number separated by a +.
@@ -12,49 +11,38 @@ description: A new Flutter application.
1211
# Read more about iOS versioning at
1312
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
1413
version: 1.0.0+1
15-
1614
environment:
17-
sdk: ">=2.1.0 <3.0.0"
18-
15+
sdk: ">=2.12.0 <3.0.0"
1916
dependencies:
2017
flutter:
2118
sdk: flutter
22-
syncfusion_flutter_calendar: 18.2.54
23-
firebase_core: "^0.5.0"
24-
cloud_firestore: ^0.14.0+1
25-
firebase_database: 4.0.0
26-
19+
syncfusion_flutter_calendar: ^19.1.58
20+
firebase_core: ^1.1.0
21+
cloud_firestore: ^1.0.7
22+
firebase_database: ^6.1.2
2723

2824
# The following adds the Cupertino Icons font to your application.
2925
# Use with the CupertinoIcons class for iOS style icons.
30-
cupertino_icons: ^0.1.3
31-
26+
cupertino_icons: ^1.0.2
3227
dev_dependencies:
3328
flutter_test:
3429
sdk: flutter
35-
3630
# For information on the generic Dart part of this file, see the
3731
# following page: https://dart.dev/tools/pub/pubspec
38-
3932
# The following section is specific to Flutter.
4033
flutter:
41-
4234
# The following line ensures that the Material Icons font is
4335
# included with your application, so that you can use the icons in
4436
# the material Icons class.
45-
uses-material-design: true
46-
37+
uses-material-design: true
4738
# To add assets to your application, add an assets section, like this:
4839
# assets:
4940
# - images/a_dot_burr.jpeg
5041
# - images/a_dot_ham.jpeg
51-
5242
# An image asset can refer to one or more resolution-specific "variants", see
5343
# https://flutter.dev/assets-and-images/#resolution-aware.
54-
5544
# For details regarding adding assets from package dependencies, see
5645
# https://flutter.dev/assets-and-images/#from-packages
57-
5846
# To add custom fonts to your application, add a fonts section here,
5947
# in this "flutter" section. Each entry in this list should have a
6048
# "family" key with the font family name, and a "fonts" key with a

0 commit comments

Comments
 (0)