Skip to content

Commit

Permalink
Fix export calendar on iOS (#1012)
Browse files Browse the repository at this point in the history
* fix

* Cleanup

* i18n

* [BOT] Applying format.

* [BOT] Applying version.

* Cleanup

* [BOT] Applying format.

---------

Co-authored-by: LouisPhilippeHeon <LouisPhilippeHeon@users.noreply.github.com>
  • Loading branch information
LouisPhilippeHeon and LouisPhilippeHeon authored Jul 9, 2024
1 parent e8a9c5b commit 8680566
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
6 changes: 4 additions & 2 deletions l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@
"calendar_export_question": "Which calendar do you want to export to?",
"calendar_name": "Calendar name",
"calendar_select": "Please select a calendar",
"calendar_cancel": "Cancel",
"calendar_export": "Export",
"calendar_cancel_button": "Cancel",
"calendar_export_button": "Export",
"calendar_permission_denied_modal_title": "Permission denied",
"calendar_permission_denied": "You denied the app the permission to edit your calendar. Change this preference in system settings to use this feature.",

"grades_title": "Grades",
"grades_msg_no_grades": "No grade available\nPull to refresh",
Expand Down
6 changes: 4 additions & 2 deletions l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@
"calendar_export_question": "Vers quel calendrier voulez-vous exporter cet événement?",
"calendar_name": "Nom du calendrier",
"calendar_select": "Veuillez sélectionner un calendrier",
"calendar_cancel": "Annuler",
"calendar_export": "Exporter",
"calendar_cancel_button": "Annuler",
"calendar_export_button": "Exporter",
"calendar_permission_denied_modal_title": "Permission Refusée",
"calendar_permission_denied": "Vous n'avez pas accordé la permission d'accéder à votre calendrier. Veuillez l'activer dans les paramètres système de l'application.",

"grades_title": "Notes",
"grades_msg_no_grades": "Aucune note disponible.\nTirez pour rafraichir",
Expand Down
22 changes: 20 additions & 2 deletions lib/features/schedule/widgets/calendar_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class CalendarSelectionWidget extends StatelessWidget {
future: CalendarUtils.nativeCalendars,
builder:
(context, AsyncSnapshot<UnmodifiableListView<Calendar>> calendars) {
if (calendars.error != null) {
return lackingPermissionsDialog(context);
}
if (!calendars.hasData) {
return const Center(
child: CircularProgressIndicator(),
Expand Down Expand Up @@ -81,7 +84,7 @@ class CalendarSelectionWidget extends StatelessWidget {
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Cancel'),
child: Text(translations.calendar_cancel_button),
),
TextButton(
onPressed: () {
Expand Down Expand Up @@ -119,7 +122,7 @@ class CalendarSelectionWidget extends StatelessWidget {
}
});
},
child: const Text('Export'),
child: Text(translations.calendar_export_button),
),
],
);
Expand All @@ -128,4 +131,19 @@ class CalendarSelectionWidget extends StatelessWidget {
},
);
}

AlertDialog lackingPermissionsDialog(BuildContext context) {
return AlertDialog(
title: Text(translations.calendar_permission_denied_modal_title),
content: Text(translations.calendar_permission_denied),
actions: <Widget>[
TextButton(
child: Text(translations.calendar_cancel_button),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
}
}
10 changes: 7 additions & 3 deletions lib/utils/calendar_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ mixin CalendarUtils {
DeviceCalendarPlugin();

static Future<UnmodifiableListView<Calendar>> get nativeCalendars async {
final Result<UnmodifiableListView<Calendar>> calendarFetchResult =
await DeviceCalendarPlugin().retrieveCalendars();
return calendarFetchResult.data!;
if (await checkPermissions()) {
final Result<UnmodifiableListView<Calendar>> calendarFetchResult =
await DeviceCalendarPlugin().retrieveCalendars();
return calendarFetchResult.data!;
}
// User denied calendar access
throw Error();
}

/// Fetches a calendar by name from the native calendar app
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: The 4th generation of ÉTSMobile, the main gateway between the Éco
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 4.45.0+1
version: 4.46.0+1

environment:
sdk: '>=3.3.0 <4.0.0'
Expand Down

0 comments on commit 8680566

Please sign in to comment.