-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathcalender_event_card.dart
164 lines (150 loc) · 4.72 KB
/
calender_event_card.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Copyright (c) 2022 Sharezone UG (haftungsbeschränkt)
// Licensed under the EUPL-1.2-or-later.
//
// You may obtain a copy of the Licence at:
// https://joinup.ec.europa.eu/software/page/eupl
//
// SPDX-License-Identifier: EUPL-1.2
import 'package:bloc_provider/bloc_provider.dart';
import 'package:flutter/material.dart';
import 'package:sharezone/calendrical_events/models/calendrical_event.dart';
import 'package:sharezone/groups/src/pages/course/course_edit/design/course_edit_design.dart';
import 'package:sharezone/main/application_bloc.dart';
import 'package:sharezone/report/page/report_page.dart';
import 'package:sharezone/report/report_icon.dart';
import 'package:sharezone/report/report_item.dart';
import 'package:sharezone/timetable/src/widgets/events/event_view.dart';
import 'package:sharezone/timetable/timetable_page/timetable_event_details.dart';
import 'package:sharezone_widgets/sharezone_widgets.dart';
import '../../../timetable_permissions.dart';
class CalenderEventCard extends StatelessWidget {
const CalenderEventCard(
this.view, {
super.key,
});
final EventView view;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(left: 12),
child: SizedBox(
width: double.infinity,
child: CustomCard(
onLongPress: () => onEventLongPress(context, view.event),
onTap: () =>
showTimetableEventDetails(context, view.event, view.design),
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_CourseName(
color: view.design?.color,
courseName: view.courseName ?? "",
),
const SizedBox(height: 6),
_Title(title: view.title),
const SizedBox(height: 6),
Text(view.dateText,
style: view.upcomingSoon
? const TextStyle(color: Colors.red)
: null),
],
),
),
),
),
);
}
}
class _CourseName extends StatelessWidget {
const _CourseName({
required this.courseName,
this.color,
});
final String courseName;
final Color? color;
@override
Widget build(BuildContext context) {
return Text(
courseName,
style: TextStyle(color: color),
maxLines: 1,
overflow: TextOverflow.ellipsis,
);
}
}
class _Title extends StatelessWidget {
const _Title({
required this.title,
});
final String title;
@override
Widget build(BuildContext context) {
return Text(
title,
style: TextStyle(
color: Theme.of(context).isDarkTheme
? Colors.lightBlueAccent
: darkBlueColor,
fontSize: 16,
fontWeight: FontWeight.w500),
overflow: TextOverflow.ellipsis,
maxLines: 1,
);
}
}
Future<void> onEventLongPress(
BuildContext context, CalendricalEvent event) async {
final api = BlocProvider.of<SharezoneContext>(context).api;
final isAuthor = api.uID == event.authorID;
final hasPermissionsToManageEvents = hasPermissionToManageEvents(
api.course.getRoleFromCourseNoSync(event.groupID)!, isAuthor);
final isExam = event.eventType == EventType.exam;
final result = await showLongPressAdaptiveDialog<_EventLongPressResult>(
context: context,
title: "${isExam ? "Prüfung" : "Termin"}: ${event.title}",
longPressList: [
const LongPress(
title: "Farbe ändern",
popResult: _EventLongPressResult.changeDesign,
icon: Icon(Icons.color_lens),
),
const LongPress(
title: "Melden",
popResult: _EventLongPressResult.report,
icon: reportIcon,
),
if (hasPermissionsToManageEvents) ...const [
LongPress(
title: "Bearbeiten",
popResult: _EventLongPressResult.edit,
icon: Icon(Icons.edit),
),
LongPress(
title: "Löschen",
popResult: _EventLongPressResult.delete,
icon: Icon(Icons.delete),
)
]
],
);
if (!context.mounted) return;
switch (result) {
case _EventLongPressResult.changeDesign:
editCourseDesign(context, event.groupID);
break;
case _EventLongPressResult.edit:
openTimetableEventEditPage(context, event);
break;
case _EventLongPressResult.delete:
deleteEvent(context, event);
break;
case _EventLongPressResult.report:
openReportPage(context, ReportItemReference.event(event.eventID));
break;
case null:
break;
}
}
enum _EventLongPressResult { changeDesign, edit, delete, report }