Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions packages/uni_app/lib/view/academic_path/widgets/exam_modal.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import 'package:add_2_calendar_new/add_2_calendar_new.dart';
import 'package:collection/collection.dart';

import 'package:device_calendar_plus/device_calendar_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'package:uni/generated/l10n.dart';
import 'package:uni/model/entities/exam.dart';
import 'package:uni/model/providers/riverpod/profile_provider.dart';

import 'package:uni/utils/date_time_formatter.dart';
import 'package:uni/utils/string_formatter.dart';
import 'package:uni/view/course_unit_info/course_unit_info.dart';
Expand All @@ -24,6 +21,7 @@ class ExamModal extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final locale = ref.watch(localeProvider);
final calendar = DeviceCalendar.instance;

return ModalDialog(
children: [
Expand Down Expand Up @@ -66,15 +64,29 @@ class ExamModal extends ConsumerWidget {
UniIcons.caretRight,
color: Theme.of(context).colorScheme.primary,
),
onPressed: () {
final event = Event(
onPressed: () async {
final calendars = await calendar.listCalendars();

var hasUniCalendar = false;
for (final calendar in calendars) {
if (calendar.name == 'Uni Exams') {
hasUniCalendar = true;
break;
}
}

final calendarId = hasUniCalendar
? calendars.firstWhere((c) => c.name == 'Uni Exams').id
: await calendar.createCalendar(name: 'Uni Exams');

await calendar.createEvent(
calendarId: calendarId,
title: exam.subject,
description: exam.examType,
location: exam.rooms.join(', '),
startDate: exam.start,
endDate: exam.finish,
);
Add2Calendar.addEvent2Cal(event);
},
),
ModalInfoRow(
Expand Down
2 changes: 1 addition & 1 deletion packages/uni_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ environment:
flutter: ">=3.41.0"

dependencies:
add_2_calendar_new: ^1.0.4
app_links: ^7.0.0
app_settings:
git:
Expand All @@ -28,6 +27,7 @@ dependencies:
crypto: ^3.0.6
cupertino_icons: ^1.0.8
currency_text_input_formatter: ^2.3.0
device_calendar_plus: ^0.3.4
diacritic: ^0.1.6
email_validator: ^3.0.0
expandable: ^5.0.1
Expand Down
40 changes: 32 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "91.0.0"
add_2_calendar_new:
dependency: transitive
description:
name: add_2_calendar_new
sha256: "1dd0bd4a26a457457e7218493c791281ae8e39e7fd3631bd6a048db7ffb67d07"
url: "https://pub.dev"
source: hosted
version: "1.0.4"
analyzer:
dependency: transitive
description:
Expand Down Expand Up @@ -434,6 +426,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.12"
device_calendar_plus:
dependency: transitive
description:
name: device_calendar_plus
sha256: "693ee6f90424d6708e64058fccdeec1ac2df72c1cdec0b5b36360ac41ee9e3c9"
url: "https://pub.dev"
source: hosted
version: "0.3.4"
device_calendar_plus_android:
dependency: transitive
description:
name: device_calendar_plus_android
sha256: "75b7d4b3be928880fe46669dc12600ff8750b6837ebf90f48b9f16b2304950ec"
url: "https://pub.dev"
source: hosted
version: "0.3.4"
device_calendar_plus_ios:
dependency: transitive
description:
name: device_calendar_plus_ios
sha256: "10c2bb9dbd1c2f5fb446ab0a0ba3eb30934f112445964aa82f3812c70eabb407"
url: "https://pub.dev"
source: hosted
version: "0.3.4"
device_calendar_plus_platform_interface:
dependency: transitive
description:
name: device_calendar_plus_platform_interface
sha256: "4cfb290ae8e4824ea9e720a119a92cf98079fbba1194f4f6fd480f5724a6e07b"
url: "https://pub.dev"
source: hosted
version: "0.3.4"
diacritic:
dependency: transitive
description:
Expand Down
Loading