diff --git a/l10n/intl_en.arb b/l10n/intl_en.arb index 905940e7a..1b02c648c 100644 --- a/l10n/intl_en.arb +++ b/l10n/intl_en.arb @@ -349,5 +349,10 @@ "ticket_status_closed": "Closed", "loading": "Loading...", - "no_schedule_available": "There are no events scheduled at the moment" + "no_schedule_available": "There are no events scheduled at the moment", + + "upcoming_events": "Upcoming events", + "semester_start_date": "Semester start date", + "semester_end_date": "Semester end date", + "registration_start_date": "Registration start date" } \ No newline at end of file diff --git a/l10n/intl_fr.arb b/l10n/intl_fr.arb index 88fdaf97e..ce5443ed7 100644 --- a/l10n/intl_fr.arb +++ b/l10n/intl_fr.arb @@ -349,5 +349,10 @@ "ticket_status_closed": "Fermé", "loading": "Chargement...", - "no_schedule_available": "Il n'y a aucun événement à l'horaire pour l'instant" + "no_schedule_available": "Il n'y a aucun événement à l'horaire pour l'instant", + + "upcoming_events": "Évènements à venir", + "semester_start_date": "Début de la session", + "semester_end_date": "Fin de la session", + "registration_start_date": "Début des inscriptions" } \ No newline at end of file diff --git a/lib/features/dashboard/dashboard_view.dart b/lib/features/dashboard/dashboard_view.dart index e48cd1d0f..f51858ac7 100644 --- a/lib/features/dashboard/dashboard_view.dart +++ b/lib/features/dashboard/dashboard_view.dart @@ -6,6 +6,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:skeletonizer/skeletonizer.dart'; import 'package:stacked/stacked.dart'; +import 'package:intl/intl.dart'; // Project imports: import 'package:notredame/constants/preferences_flags.dart'; @@ -201,7 +202,7 @@ class _DashboardViewState extends State ); Widget _buildProgressBarCard( - DashboardViewModel model, PreferencesFlag flag) => + DashboardViewModel model, PreferencesFlag flag) => DismissibleCard( key: UniqueKey(), onDismissed: (DismissDirection direction) { @@ -226,7 +227,7 @@ class _DashboardViewState extends State borderRadius: const BorderRadius.all(Radius.circular(10)), child: GestureDetector( onTap: () => setState( - () => setState(() { + () => setState(() { model.changeProgressBarText(); setText(model); }), @@ -267,6 +268,51 @@ class _DashboardViewState extends State child: Text(AppIntl.of(context)!.session_without), ), ), + Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 16, 8), + child: Builder( + builder: (context) { + if (model.upcomingEvents.isEmpty) return const SizedBox.shrink(); + final currentLocale = AppIntl.of(context)!.localeName; + + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + AppIntl.of(context)!.upcoming_events, + style: Theme.of(context).textTheme.titleLarge?.copyWith( + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 8), + Align( + alignment: Alignment.centerLeft, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: model.upcomingEvents.map((entry) { + int index = entry.key; + DateTime date = entry.value; + + List labels = [ + AppIntl.of(context)!.semester_start_date, + AppIntl.of(context)!.semester_end_date, + AppIntl.of(context)!.registration_start_date + ]; + + String formattedDate = DateFormat('dd MMMM yyyy', currentLocale).format(date); + + return Text( + "${labels[index]}: $formattedDate", + style: const TextStyle(color: Colors.black), + ); + }).toList(), + ), + ), + ], + ); + }, + ), + ) ]), ); diff --git a/lib/features/dashboard/dashboard_viewmodel.dart b/lib/features/dashboard/dashboard_viewmodel.dart index 8e4283aeb..46193139f 100644 --- a/lib/features/dashboard/dashboard_viewmodel.dart +++ b/lib/features/dashboard/dashboard_viewmodel.dart @@ -44,6 +44,9 @@ class DashboardViewModel extends FutureViewModel> { /// Percentage of completed days for the session double _progress = 0.0; + /// Session important days + List> _upcomingEvents = []; + /// Numbers of days elapsed and total number of days of the current session List _sessionDays = [0, 0]; @@ -60,6 +63,8 @@ class DashboardViewModel extends FutureViewModel> { List get sessionDays => _sessionDays; + List> get upcomingEvents => _upcomingEvents; + /// Activities for today List _todayDateEvents = []; @@ -298,8 +303,22 @@ class DashboardViewModel extends FutureViewModel> { setBusyForObject(progress, true); final sessions = await _courseRepository.getSessions(); + final List importantDates = [sessions[1].startDate, sessions[1].endDate, sessions[1].startDateRegistration]; _sessionDays = getSessionDays(); _progress = getSessionProgress(); + + _upcomingEvents = importantDates.asMap().entries.where((entry) { + DateTime date = entry.value; + DateTime now = DateTime.now(); + + return now.isAfter(date.subtract(const Duration(days: 3))) && now.isBefore(date.add(const Duration(days: 1))); + }).toList(); + + _upcomingEvents = importantDates.asMap().entries.where((entry) { + DateTime date = entry.value; + DateTime now = DateTime.now(); + return now.isAfter(date.subtract(const Duration(days: 3))) && now.isBefore(date.add(const Duration(days: 1))); + }).toList(); return sessions; } catch (error) { onError(error);