From 86c0cfad014413b0d0aa59c13787f1bafa947d1e Mon Sep 17 00:00:00 2001 From: vitormpp Date: Fri, 1 Dec 2023 13:10:54 +0000 Subject: [PATCH 1/8] Modified getExamRows method to enable the display of multiple exams if they occur on the same day. --- uni/lib/view/home/widgets/exam_card.dart | 63 ++++++++++++++++-------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/uni/lib/view/home/widgets/exam_card.dart b/uni/lib/view/home/widgets/exam_card.dart index 0b3199cc4..f5adcfc46 100644 --- a/uni/lib/view/home/widgets/exam_card.dart +++ b/uni/lib/view/home/widgets/exam_card.dart @@ -75,18 +75,36 @@ class ExamCard extends GenericCard { ); } + /// Returns true if two exams are in the same day + bool isSameDay(DateTime datetime1, DateTime datetime2) { + return datetime1.year == datetime2.year + && datetime1.month == datetime2.month + && datetime1.day == datetime2.day; + } + /// Returns a list of widgets with the primary and secondary exams to /// be displayed in the exam card. List getExamRows(BuildContext context, List exams) { final rows = []; - for (var i = 0; i < 1 && i < exams.length; i++) { - rows.add(createRowFromExam(context, exams[i])); - } - if (exams.length > 1) { + + rows.add(createRowFromExam(context, exams[0], isFirst: true)); + + var sameDayExamCount = exams.sublist(1).takeWhile( + (exam) => isSameDay(exam.begin, exams[0].begin), + ).toList().fold(0, (count, exam) { + rows.addAll([ + Container( + margin: const EdgeInsets.only(top: 8), + ), + createRowFromExam(context, exam), + ]); + return count + 1; + }); + + if (exams.length > 1 && sameDayExamCount > 0) { rows.add( Container( - margin: - const EdgeInsets.only(right: 80, left: 80, top: 15, bottom: 7), + margin: const EdgeInsets.only(right: 80, left: 80, top: 15, bottom: 7), decoration: BoxDecoration( border: Border( bottom: BorderSide( @@ -98,28 +116,33 @@ class ExamCard extends GenericCard { ), ); } - for (var i = 1; i < 4 && i < exams.length; i++) { - rows.add(createSecondaryRowFromExam(context, exams[i])); - } + + // Processing secondary exams without a loop + exams.sublist(1 + sameDayExamCount) + .take(4 - sameDayExamCount - 1) + .forEach((exam) => rows.add(createSecondaryRowFromExam(context, exam))); + return rows; } /// Creates a row with the closest exam (which appears separated from the /// others in the card). - Widget createRowFromExam(BuildContext context, Exam exam) { + Widget createRowFromExam(BuildContext context, Exam exam, {bool isFirst = false}) { final locale = Provider.of(context).getLocale(); return Column( children: [ - if (locale == AppLocale.pt) ...[ - DateRectangle( - date: '''${exam.weekDay(locale)}, ''' - '''${exam.begin.day} de ${exam.month(locale)}''', - ), - ] else ...[ - DateRectangle( - date: '''${exam.weekDay(locale)}, ''' - '''${exam.begin.day} ${exam.month(locale)}''', - ), + if(isFirst) ...[ + if (locale == AppLocale.pt) ...[ + DateRectangle( + date: '''${exam.weekDay(locale)}, ''' + '''${exam.begin.day} de ${exam.month(locale)}''', + ), + ] else ...[ + DateRectangle( + date: '''${exam.weekDay(locale)}, ''' + '''${exam.begin.day} ${exam.month(locale)}''', + ), + ], ], RowContainer( child: ExamRow( From b05d502f50b4d05e753490c9e4f149d377f953ad Mon Sep 17 00:00:00 2001 From: vitor Date: Sun, 17 Dec 2023 18:09:00 +0000 Subject: [PATCH 2/8] Adjusted display logic for NextExamsWidget and ReaminingExamsWidget --- uni/lib/view/home/widgets/exam_card.dart | 306 +++++++----------- .../view/home/widgets/next_exams_card.dart | 48 +++ .../home/widgets/remaining_exams_card.dart | 45 +++ 3 files changed, 213 insertions(+), 186 deletions(-) create mode 100644 uni/lib/view/home/widgets/next_exams_card.dart create mode 100644 uni/lib/view/home/widgets/remaining_exams_card.dart diff --git a/uni/lib/view/home/widgets/exam_card.dart b/uni/lib/view/home/widgets/exam_card.dart index f5adcfc46..069320ba8 100644 --- a/uni/lib/view/home/widgets/exam_card.dart +++ b/uni/lib/view/home/widgets/exam_card.dart @@ -1,186 +1,120 @@ -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; -import 'package:uni/generated/l10n.dart'; -import 'package:uni/model/entities/app_locale.dart'; -import 'package:uni/model/entities/exam.dart'; -import 'package:uni/model/providers/lazy/exam_provider.dart'; -import 'package:uni/utils/drawer_items.dart'; -import 'package:uni/view/common_widgets/date_rectangle.dart'; -import 'package:uni/view/common_widgets/generic_card.dart'; -import 'package:uni/view/common_widgets/request_dependent_widget_builder.dart'; -import 'package:uni/view/common_widgets/row_container.dart'; -import 'package:uni/view/exams/widgets/exam_row.dart'; -import 'package:uni/view/exams/widgets/exam_title.dart'; -import 'package:uni/view/home/widgets/exam_card_shimmer.dart'; -import 'package:uni/view/lazy_consumer.dart'; -import 'package:uni/view/locale_notifier.dart'; - -/// Manages the exam card section inside the personal area. -class ExamCard extends GenericCard { - ExamCard({super.key}); - - const ExamCard.fromEditingInformation( - super.key, { - required super.editingMode, - super.onDelete, - }) : super.fromEditingInformation(); - - @override - String getTitle(BuildContext context) => - S.of(context).nav_title(DrawerItem.navExams.title); - - @override - Future onClick(BuildContext context) => - Navigator.pushNamed(context, '/${DrawerItem.navExams.title}'); - - @override - void onRefresh(BuildContext context) { - Provider.of(context, listen: false).forceRefresh(context); - } - - /// Returns a widget with all the exams card content. - /// - /// If there are no exams, a message telling the user - /// that no exams exist is displayed. - @override - Widget buildCardContent(BuildContext context) { - return LazyConsumer( - builder: (context, examProvider) { - final filteredExams = examProvider.getFilteredExams(); - final hiddenExams = examProvider.hiddenExams; - final exams = filteredExams - .where((exam) => !hiddenExams.contains(exam.id)) - .toList(); - return RequestDependentWidgetBuilder( - status: examProvider.status, - builder: () => generateExams(exams, context), - hasContentPredicate: exams.isNotEmpty, - onNullContent: Center( - child: Text( - S.of(context).no_selected_exams, - style: Theme.of(context).textTheme.titleLarge, - ), - ), - contentLoadingWidget: const ExamCardShimmer().build(context), - ); - }, - ); - } - - /// Returns a widget with all the exams. - Widget generateExams(List exams, BuildContext context) { - return Column( - mainAxisSize: MainAxisSize.min, - children: getExamRows(context, exams), - ); - } - - /// Returns true if two exams are in the same day - bool isSameDay(DateTime datetime1, DateTime datetime2) { - return datetime1.year == datetime2.year - && datetime1.month == datetime2.month - && datetime1.day == datetime2.day; - } - - /// Returns a list of widgets with the primary and secondary exams to - /// be displayed in the exam card. - List getExamRows(BuildContext context, List exams) { - final rows = []; - - rows.add(createRowFromExam(context, exams[0], isFirst: true)); - - var sameDayExamCount = exams.sublist(1).takeWhile( - (exam) => isSameDay(exam.begin, exams[0].begin), - ).toList().fold(0, (count, exam) { - rows.addAll([ - Container( - margin: const EdgeInsets.only(top: 8), - ), - createRowFromExam(context, exam), - ]); - return count + 1; - }); - - if (exams.length > 1 && sameDayExamCount > 0) { - rows.add( - Container( - margin: const EdgeInsets.only(right: 80, left: 80, top: 15, bottom: 7), - decoration: BoxDecoration( - border: Border( - bottom: BorderSide( - width: 1.5, - color: Theme.of(context).dividerColor, - ), - ), - ), - ), - ); - } - - // Processing secondary exams without a loop - exams.sublist(1 + sameDayExamCount) - .take(4 - sameDayExamCount - 1) - .forEach((exam) => rows.add(createSecondaryRowFromExam(context, exam))); - - return rows; - } - - /// Creates a row with the closest exam (which appears separated from the - /// others in the card). - Widget createRowFromExam(BuildContext context, Exam exam, {bool isFirst = false}) { - final locale = Provider.of(context).getLocale(); - return Column( - children: [ - if(isFirst) ...[ - if (locale == AppLocale.pt) ...[ - DateRectangle( - date: '''${exam.weekDay(locale)}, ''' - '''${exam.begin.day} de ${exam.month(locale)}''', - ), - ] else ...[ - DateRectangle( - date: '''${exam.weekDay(locale)}, ''' - '''${exam.begin.day} ${exam.month(locale)}''', - ), - ], - ], - RowContainer( - child: ExamRow( - exam: exam, - teacher: '', - mainPage: true, - ), - ), - ], - ); - } - - /// Creates a row for the exams which will be displayed under the closest - /// date exam with a separator between them. - Widget createSecondaryRowFromExam(BuildContext context, Exam exam) { - final locale = Provider.of(context).getLocale(); - return Container( - margin: const EdgeInsets.only(top: 8), - child: RowContainer( - color: Theme.of(context).colorScheme.background, - child: Container( - padding: const EdgeInsets.all(11), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - '${exam.begin.day} de ${exam.month(locale)}', - style: Theme.of(context).textTheme.bodyLarge, - ), - ExamTitle( - subject: exam.subject, - type: exam.type, - reverseOrder: true, - ), - ], - ), - ), - ), - ); - } -} +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:uni/generated/l10n.dart'; +import 'package:uni/model/entities/exam.dart'; +import 'package:uni/model/providers/lazy/exam_provider.dart'; +import 'package:uni/utils/drawer_items.dart'; +import 'package:uni/view/common_widgets/generic_card.dart'; +import 'package:uni/view/common_widgets/request_dependent_widget_builder.dart'; +import 'package:uni/view/home/widgets/exam_card_shimmer.dart'; +import 'package:uni/view/home/widgets/next_exams_card.dart'; +import 'package:uni/view/home/widgets/remaining_exams_card.dart'; +import 'package:uni/view/lazy_consumer.dart'; + + +class ExamCard extends GenericCard { + ExamCard({super.key}); + + const ExamCard.fromEditingInformation( + super.key, { + required super.editingMode, + super.onDelete, + }) : super.fromEditingInformation(); + + @override + String getTitle(BuildContext context) => + S.of(context).nav_title(DrawerItem.navExams.title); + + @override + Future onClick(BuildContext context) => + Navigator.pushNamed(context, '/${DrawerItem.navExams.title}'); + + @override + void onRefresh(BuildContext context) { + Provider.of(context, listen: false).forceRefresh(context); + } + + @override + Widget buildCardContent(BuildContext context) { + return LazyConsumer( + builder: (context, examProvider) { + final filteredExams = examProvider.getFilteredExams(); + final hiddenExams = examProvider.hiddenExams; + final allExams = filteredExams + .where((exam) => !hiddenExams.contains(exam.id)) + .toList(); + return RequestDependentWidgetBuilder( + status: examProvider.status, + builder: () => generateExams(allExams, context), + hasContentPredicate: allExams.isNotEmpty, + onNullContent: Center( + child: Text( + S.of(context).no_selected_exams, + style: Theme.of(context).textTheme.titleLarge, + ), + ), + contentLoadingWidget: const ExamCardShimmer().build(context), + ); + }, + ); + } + + Widget generateExams(List allExams, BuildContext context) { + final nextExams = getPrimaryExams(allExams, + allExams.isNotEmpty ? allExams.first : null, ); + final primaryExams = NextExamsWidget(exams: nextExams); + + + final remainingExamsCount = 4 - nextExams.length; + final List remainingExams; + if (remainingExamsCount > 0) { + remainingExams = allExams + .where((exam) => !nextExams.contains(exam)) + .take(remainingExamsCount) + .toList(); + } else { + remainingExams = []; + } + final secondaryExams = RemainingExamsWidget(exams: remainingExams); + + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + primaryExams, + if (remainingExamsCount > 0) + Column( + children: [ + Container( + margin: + const EdgeInsets.only(right: 80, left: 80, top: 7, bottom: 7), + decoration: BoxDecoration( + border: Border( + bottom: BorderSide( + color: Theme.of(context).dividerColor, + ), + ), + ), + ), + secondaryExams, + ], + ), + ], + ); + } + + List getPrimaryExams(List allExams, Exam? nextExam) { + if (nextExam == null) { + return []; + } + + final sameDayExams = allExams.where((exam) { + final nextExamDate = + DateTime(nextExam.begin.year, nextExam.begin.month, nextExam.begin.day); + final examDate = + DateTime(exam.begin.year, exam.begin.month, exam.begin.day); + return nextExamDate.isAtSameMomentAs(examDate); + }).toList(); + + return sameDayExams; + } +} diff --git a/uni/lib/view/home/widgets/next_exams_card.dart b/uni/lib/view/home/widgets/next_exams_card.dart new file mode 100644 index 000000000..829087587 --- /dev/null +++ b/uni/lib/view/home/widgets/next_exams_card.dart @@ -0,0 +1,48 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:uni/model/entities/app_locale.dart'; +import 'package:uni/model/entities/exam.dart'; +import 'package:uni/view/common_widgets/date_rectangle.dart'; +import 'package:uni/view/common_widgets/row_container.dart'; +import 'package:uni/view/exams/widgets/exam_row.dart'; +import 'package:uni/view/locale_notifier.dart'; + +class NextExamsWidget extends StatelessWidget { + const NextExamsWidget({required this.exams, super.key}); + + final List exams; + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + DateRectangle( + date: exams.isNotEmpty ? getFormattedDate(exams.first, context) : '', + ), + const SizedBox(height: 8), + Column( + children: exams.map((exam) { + return Padding( + padding: const EdgeInsets.only(bottom: 8), + child: RowContainer( + child: ExamRow( + exam: exam, + teacher: '', + mainPage: true, + ), + ), + ); + }).toList(), + ), + ], + ); + } + + String getFormattedDate(Exam exam, BuildContext context) { + final locale = Provider.of(context).getLocale(); + return locale == AppLocale.pt + ? '${exam.weekDay(locale)}, ${exam.begin.day} de ${exam.month(locale)}' + : '${exam.weekDay(locale)}, ${exam.begin.day} ${exam.month(locale)}'; + } +} diff --git a/uni/lib/view/home/widgets/remaining_exams_card.dart b/uni/lib/view/home/widgets/remaining_exams_card.dart new file mode 100644 index 000000000..610f342db --- /dev/null +++ b/uni/lib/view/home/widgets/remaining_exams_card.dart @@ -0,0 +1,45 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:uni/model/entities/exam.dart'; +import 'package:uni/view/common_widgets/row_container.dart'; +import 'package:uni/view/exams/widgets/exam_title.dart'; +import 'package:uni/view/locale_notifier.dart'; + +class RemainingExamsWidget extends StatelessWidget { + + const RemainingExamsWidget({required this.exams, super.key}); + final List exams; + + @override + Widget build(BuildContext context) { + + return Column( + children: exams.map((exam) { + final locale = Provider.of(context).getLocale(); + return Container( + margin: const EdgeInsets.only(top: 8), + child: RowContainer( + color: Theme.of(context).colorScheme.background, + child: Container( + padding: const EdgeInsets.all(11), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + '${exam.begin.day} de ${exam.month(locale)}', + style: Theme.of(context).textTheme.bodyLarge, + ), + ExamTitle( + subject: exam.subject, + type: exam.type, + reverseOrder: true, + ), + ], + ), + ), + ), + ); + }).toList(), + ); + } +} From b488d6fe1221f8f58fbe51ad4baf654d68c6a7d5 Mon Sep 17 00:00:00 2001 From: vitormpp Date: Fri, 22 Dec 2023 16:50:01 +0000 Subject: [PATCH 3/8] Resolved Dart formatting issue --- uni/lib/view/home/widgets/exam_card.dart | 26 +++++++++---------- .../home/widgets/remaining_exams_card.dart | 2 -- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/uni/lib/view/home/widgets/exam_card.dart b/uni/lib/view/home/widgets/exam_card.dart index 069320ba8..d1a93700d 100644 --- a/uni/lib/view/home/widgets/exam_card.dart +++ b/uni/lib/view/home/widgets/exam_card.dart @@ -11,15 +11,14 @@ import 'package:uni/view/home/widgets/next_exams_card.dart'; import 'package:uni/view/home/widgets/remaining_exams_card.dart'; import 'package:uni/view/lazy_consumer.dart'; - class ExamCard extends GenericCard { ExamCard({super.key}); const ExamCard.fromEditingInformation( - super.key, { - required super.editingMode, - super.onDelete, - }) : super.fromEditingInformation(); + super.key, { + required super.editingMode, + super.onDelete, + }) : super.fromEditingInformation(); @override String getTitle(BuildContext context) => @@ -60,11 +59,12 @@ class ExamCard extends GenericCard { } Widget generateExams(List allExams, BuildContext context) { - final nextExams = getPrimaryExams(allExams, - allExams.isNotEmpty ? allExams.first : null, ); + final nextExams = getPrimaryExams( + allExams, + allExams.isNotEmpty ? allExams.first : null, + ); final primaryExams = NextExamsWidget(exams: nextExams); - final remainingExamsCount = 4 - nextExams.length; final List remainingExams; if (remainingExamsCount > 0) { @@ -85,8 +85,8 @@ class ExamCard extends GenericCard { Column( children: [ Container( - margin: - const EdgeInsets.only(right: 80, left: 80, top: 7, bottom: 7), + margin: const EdgeInsets.only( + right: 80, left: 80, top: 7, bottom: 7), decoration: BoxDecoration( border: Border( bottom: BorderSide( @@ -108,10 +108,10 @@ class ExamCard extends GenericCard { } final sameDayExams = allExams.where((exam) { - final nextExamDate = - DateTime(nextExam.begin.year, nextExam.begin.month, nextExam.begin.day); + final nextExamDate = DateTime( + nextExam.begin.year, nextExam.begin.month, nextExam.begin.day); final examDate = - DateTime(exam.begin.year, exam.begin.month, exam.begin.day); + DateTime(exam.begin.year, exam.begin.month, exam.begin.day); return nextExamDate.isAtSameMomentAs(examDate); }).toList(); diff --git a/uni/lib/view/home/widgets/remaining_exams_card.dart b/uni/lib/view/home/widgets/remaining_exams_card.dart index 610f342db..8ae7230de 100644 --- a/uni/lib/view/home/widgets/remaining_exams_card.dart +++ b/uni/lib/view/home/widgets/remaining_exams_card.dart @@ -6,13 +6,11 @@ import 'package:uni/view/exams/widgets/exam_title.dart'; import 'package:uni/view/locale_notifier.dart'; class RemainingExamsWidget extends StatelessWidget { - const RemainingExamsWidget({required this.exams, super.key}); final List exams; @override Widget build(BuildContext context) { - return Column( children: exams.map((exam) { final locale = Provider.of(context).getLocale(); From 896e9ef8947ca5937f5268d3d78e4e5ca587300c Mon Sep 17 00:00:00 2001 From: vitormpp Date: Fri, 22 Dec 2023 16:56:52 +0000 Subject: [PATCH 4/8] Fixed missing required trailing commas --- uni/lib/view/home/widgets/exam_card.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/uni/lib/view/home/widgets/exam_card.dart b/uni/lib/view/home/widgets/exam_card.dart index d1a93700d..aed4346e8 100644 --- a/uni/lib/view/home/widgets/exam_card.dart +++ b/uni/lib/view/home/widgets/exam_card.dart @@ -86,7 +86,11 @@ class ExamCard extends GenericCard { children: [ Container( margin: const EdgeInsets.only( - right: 80, left: 80, top: 7, bottom: 7), + right: 80, + left: 80, + top: 7, + bottom: 7, + ), decoration: BoxDecoration( border: Border( bottom: BorderSide( @@ -109,7 +113,10 @@ class ExamCard extends GenericCard { final sameDayExams = allExams.where((exam) { final nextExamDate = DateTime( - nextExam.begin.year, nextExam.begin.month, nextExam.begin.day); + nextExam.begin.year, + nextExam.begin.month, + nextExam.begin.day, + ); final examDate = DateTime(exam.begin.year, exam.begin.month, exam.begin.day); return nextExamDate.isAtSameMomentAs(examDate); From 18d807139130c1099341e61dc312bcec77f501ae Mon Sep 17 00:00:00 2001 From: vitormpp Date: Fri, 12 Jan 2024 13:53:42 +0000 Subject: [PATCH 5/8] Added auxiliary method. Made some adjustments to the code --- uni/lib/view/home/widgets/exam_card.dart | 114 +++++++++++------------ 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/uni/lib/view/home/widgets/exam_card.dart b/uni/lib/view/home/widgets/exam_card.dart index aed4346e8..43afcaac1 100644 --- a/uni/lib/view/home/widgets/exam_card.dart +++ b/uni/lib/view/home/widgets/exam_card.dart @@ -20,6 +20,8 @@ class ExamCard extends GenericCard { super.onDelete, }) : super.fromEditingInformation(); + static const int maxExamsToDisplay = 4; + @override String getTitle(BuildContext context) => S.of(context).nav_title(DrawerItem.navExams.title); @@ -42,9 +44,56 @@ class ExamCard extends GenericCard { final allExams = filteredExams .where((exam) => !hiddenExams.contains(exam.id)) .toList(); + final nextExams = getPrimaryExams( + allExams, + allExams.isNotEmpty ? allExams.first : null, + ); + return RequestDependentWidgetBuilder( status: examProvider.status, - builder: () => generateExams(allExams, context), + builder: () { + if (nextExams.isEmpty) { + return Center( + child: Text( + S.of(context).no_selected_exams, + style: Theme.of(context).textTheme.titleLarge, + ), + ); + } + + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + NextExamsWidget(exams: nextExams), + if (nextExams.length < maxExamsToDisplay) + Column( + children: [ + Container( + margin: const EdgeInsets.only( + right: 80, + left: 80, + top: 7, + bottom: 7, + ), + decoration: BoxDecoration( + border: Border( + bottom: BorderSide( + color: Theme.of(context).dividerColor, + ), + ), + ), + ), + RemainingExamsWidget( + exams: allExams + .where((exam) => !nextExams.contains(exam)) + .take(maxExamsToDisplay - nextExams.length) + .toList(), + ), + ], + ), + ], + ); + }, hasContentPredicate: allExams.isNotEmpty, onNullContent: Center( child: Text( @@ -58,70 +107,21 @@ class ExamCard extends GenericCard { ); } - Widget generateExams(List allExams, BuildContext context) { - final nextExams = getPrimaryExams( - allExams, - allExams.isNotEmpty ? allExams.first : null, - ); - final primaryExams = NextExamsWidget(exams: nextExams); - - final remainingExamsCount = 4 - nextExams.length; - final List remainingExams; - if (remainingExamsCount > 0) { - remainingExams = allExams - .where((exam) => !nextExams.contains(exam)) - .take(remainingExamsCount) - .toList(); - } else { - remainingExams = []; - } - final secondaryExams = RemainingExamsWidget(exams: remainingExams); - - return Column( - mainAxisSize: MainAxisSize.min, - children: [ - primaryExams, - if (remainingExamsCount > 0) - Column( - children: [ - Container( - margin: const EdgeInsets.only( - right: 80, - left: 80, - top: 7, - bottom: 7, - ), - decoration: BoxDecoration( - border: Border( - bottom: BorderSide( - color: Theme.of(context).dividerColor, - ), - ), - ), - ), - secondaryExams, - ], - ), - ], - ); - } - List getPrimaryExams(List allExams, Exam? nextExam) { if (nextExam == null) { return []; } final sameDayExams = allExams.where((exam) { - final nextExamDate = DateTime( - nextExam.begin.year, - nextExam.begin.month, - nextExam.begin.day, - ); - final examDate = - DateTime(exam.begin.year, exam.begin.month, exam.begin.day); - return nextExamDate.isAtSameMomentAs(examDate); + return isSameDay(nextExam.begin, exam.begin); }).toList(); return sameDayExams; } + + bool isSameDay(DateTime? dateA, DateTime? dateB) { + return dateA?.year == dateB?.year && + dateA?.month == dateB?.month && + dateA?.day == dateB?.day; + } } From 5a636bd8760f8501585f4d93b7f222f5d63bb788 Mon Sep 17 00:00:00 2001 From: vitormpp Date: Fri, 26 Jan 2024 13:18:07 +0000 Subject: [PATCH 6/8] Made some adjustments to accommodate recent updates --- uni/lib/view/home/widgets/exam_card.dart | 115 +++++++----------- .../view/home/widgets/next_exams_card.dart | 2 +- 2 files changed, 47 insertions(+), 70 deletions(-) diff --git a/uni/lib/view/home/widgets/exam_card.dart b/uni/lib/view/home/widgets/exam_card.dart index e6f0f69c9..1359d6f2a 100644 --- a/uni/lib/view/home/widgets/exam_card.dart +++ b/uni/lib/view/home/widgets/exam_card.dart @@ -5,7 +5,6 @@ import 'package:uni/model/entities/exam.dart'; import 'package:uni/model/providers/lazy/exam_provider.dart'; import 'package:uni/utils/drawer_items.dart'; import 'package:uni/view/common_widgets/generic_card.dart'; -import 'package:uni/view/common_widgets/request_dependent_widget_builder.dart'; import 'package:uni/view/home/widgets/exam_card_shimmer.dart'; import 'package:uni/view/home/widgets/next_exams_card.dart'; import 'package:uni/view/home/widgets/remaining_exams_card.dart'; @@ -15,10 +14,10 @@ class ExamCard extends GenericCard { ExamCard({super.key}); const ExamCard.fromEditingInformation( - super.key, { - required super.editingMode, - super.onDelete, - }) : super.fromEditingInformation(); + super.key, { + required super.editingMode, + super.onDelete, + }) : super.fromEditingInformation(); static const int maxExamsToDisplay = 4; @@ -37,73 +36,53 @@ class ExamCard extends GenericCard { @override Widget buildCardContent(BuildContext context) { - return LazyConsumer( - builder: (context, examProvider) { - final filteredExams = examProvider.getFilteredExams(); - final hiddenExams = examProvider.hiddenExams; - final allExams = filteredExams - .where((exam) => !hiddenExams.contains(exam.id)) - .toList(); + return LazyConsumer>( + builder: (context, allExams) { final nextExams = getPrimaryExams( allExams, allExams.isNotEmpty ? allExams.first : null, ); - - return RequestDependentWidgetBuilder( - status: examProvider.status, - builder: () { - if (nextExams.isEmpty) { - return Center( - child: Text( - S.of(context).no_selected_exams, - style: Theme.of(context).textTheme.titleLarge, - ), - ); - } - - return Column( - mainAxisSize: MainAxisSize.min, - children: [ - NextExamsWidget(exams: nextExams), - if (nextExams.length < maxExamsToDisplay) - Column( - children: [ - Container( - margin: const EdgeInsets.only( - right: 80, - left: 80, - top: 7, - bottom: 7, - ), - decoration: BoxDecoration( - border: Border( - bottom: BorderSide( - color: Theme.of(context).dividerColor, - ), - ), + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + NextExamsWidget(exams: nextExams), + if (nextExams.length < maxExamsToDisplay) + Column( + children: [ + Container( + margin: const EdgeInsets.only( + right: 80, + left: 80, + top: 7, + bottom: 7, + ), + decoration: BoxDecoration( + border: Border( + bottom: BorderSide( + color: Theme.of(context).dividerColor, ), ), - RemainingExamsWidget( - exams: allExams - .where((exam) => !nextExams.contains(exam)) - .take(maxExamsToDisplay - nextExams.length) - .toList(), - ), - ], + ), + ), + RemainingExamsWidget( + exams: allExams + .where((exam) => !nextExams.contains(exam)) + .take(maxExamsToDisplay - nextExams.length) + .toList(), ), - ], - ); - }, - hasContentPredicate: allExams.isNotEmpty, - onNullContent: Center( - child: Text( - S.of(context).no_selected_exams, - style: Theme.of(context).textTheme.titleLarge, - ), - ), - contentLoadingWidget: const ExamCardShimmer().build(context), + ], + ), + ], ); }, + hasContent: (allExams) => allExams.isNotEmpty, + onNullContent: Center( + child: Text( + S.of(context).no_selected_exams, + style: Theme.of(context).textTheme.titleLarge, + ), + ), + contentLoadingWidget: const ExamCardShimmer(), ); } @@ -112,11 +91,9 @@ class ExamCard extends GenericCard { return []; } - final sameDayExams = allExams.where((exam) { - return isSameDay(nextExam.begin, exam.begin); - }).toList(); - - return sameDayExams; + return allExams + .where((exam) => isSameDay(nextExam.begin, exam.begin)) + .toList(); } bool isSameDay(DateTime? dateA, DateTime? dateB) { @@ -124,4 +101,4 @@ class ExamCard extends GenericCard { dateA?.month == dateB?.month && dateA?.day == dateB?.day; } -} \ No newline at end of file +} diff --git a/uni/lib/view/home/widgets/next_exams_card.dart b/uni/lib/view/home/widgets/next_exams_card.dart index 829087587..e258d65bf 100644 --- a/uni/lib/view/home/widgets/next_exams_card.dart +++ b/uni/lib/view/home/widgets/next_exams_card.dart @@ -20,7 +20,6 @@ class NextExamsWidget extends StatelessWidget { DateRectangle( date: exams.isNotEmpty ? getFormattedDate(exams.first, context) : '', ), - const SizedBox(height: 8), Column( children: exams.map((exam) { return Padding( @@ -30,6 +29,7 @@ class NextExamsWidget extends StatelessWidget { exam: exam, teacher: '', mainPage: true, + onChangeVisibility: () {}, ), ), ); From 4b2ec9a70371bb2c1d95b82a25f7f155187c852b Mon Sep 17 00:00:00 2001 From: vitormpp Date: Fri, 26 Jan 2024 14:04:37 +0000 Subject: [PATCH 7/8] Format file --- uni/lib/view/home/widgets/exam_card.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/uni/lib/view/home/widgets/exam_card.dart b/uni/lib/view/home/widgets/exam_card.dart index 1359d6f2a..ce6df7641 100644 --- a/uni/lib/view/home/widgets/exam_card.dart +++ b/uni/lib/view/home/widgets/exam_card.dart @@ -14,10 +14,10 @@ class ExamCard extends GenericCard { ExamCard({super.key}); const ExamCard.fromEditingInformation( - super.key, { - required super.editingMode, - super.onDelete, - }) : super.fromEditingInformation(); + super.key, { + required super.editingMode, + super.onDelete, + }) : super.fromEditingInformation(); static const int maxExamsToDisplay = 4; From eec6c1ab360a572b45596cff882049d70ece5068 Mon Sep 17 00:00:00 2001 From: Bruno Mendes Date: Wed, 7 Feb 2024 15:33:07 +0000 Subject: [PATCH 8/8] Fix remaining exams display --- uni/lib/model/entities/exam.dart | 3 ++- uni/lib/view/exams/widgets/exam_row.dart | 2 +- uni/lib/view/home/widgets/exam_card.dart | 12 ++++-------- uni/lib/view/home/widgets/remaining_exams_card.dart | 3 ++- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/uni/lib/model/entities/exam.dart b/uni/lib/model/entities/exam.dart index 0d27cb1bc..ed1df9e70 100644 --- a/uni/lib/model/entities/exam.dart +++ b/uni/lib/model/entities/exam.dart @@ -88,7 +88,8 @@ class Exam { @override bool operator ==(Object other) => - identical(this, other) || other is Exam && id == other.id; + identical(this, other) || + other is Exam && id == other.id && subject == other.subject; @override int get hashCode => id.hashCode; diff --git a/uni/lib/view/exams/widgets/exam_row.dart b/uni/lib/view/exams/widgets/exam_row.dart index 4af26b10a..e6175c2a1 100644 --- a/uni/lib/view/exams/widgets/exam_row.dart +++ b/uni/lib/view/exams/widgets/exam_row.dart @@ -122,7 +122,7 @@ class _ExamRowState extends State { } Widget? getExamRooms(BuildContext context) { - if (widget.exam.rooms[0] == '') return null; + if (widget.exam.rooms.isEmpty || widget.exam.rooms[0] == '') return null; return Wrap( spacing: 13, children: roomsList(context, widget.exam.rooms), diff --git a/uni/lib/view/home/widgets/exam_card.dart b/uni/lib/view/home/widgets/exam_card.dart index ce6df7641..8d7258b5e 100644 --- a/uni/lib/view/home/widgets/exam_card.dart +++ b/uni/lib/view/home/widgets/exam_card.dart @@ -40,13 +40,13 @@ class ExamCard extends GenericCard { builder: (context, allExams) { final nextExams = getPrimaryExams( allExams, - allExams.isNotEmpty ? allExams.first : null, ); return Column( mainAxisSize: MainAxisSize.min, children: [ NextExamsWidget(exams: nextExams), - if (nextExams.length < maxExamsToDisplay) + if (nextExams.length < maxExamsToDisplay && + allExams.length > nextExams.length) Column( children: [ Container( @@ -86,13 +86,9 @@ class ExamCard extends GenericCard { ); } - List getPrimaryExams(List allExams, Exam? nextExam) { - if (nextExam == null) { - return []; - } - + List getPrimaryExams(List allExams) { return allExams - .where((exam) => isSameDay(nextExam.begin, exam.begin)) + .where((exam) => isSameDay(allExams[0].begin, exam.begin)) .toList(); } diff --git a/uni/lib/view/home/widgets/remaining_exams_card.dart b/uni/lib/view/home/widgets/remaining_exams_card.dart index 8ae7230de..1b2afeb97 100644 --- a/uni/lib/view/home/widgets/remaining_exams_card.dart +++ b/uni/lib/view/home/widgets/remaining_exams_card.dart @@ -7,6 +7,7 @@ import 'package:uni/view/locale_notifier.dart'; class RemainingExamsWidget extends StatelessWidget { const RemainingExamsWidget({required this.exams, super.key}); + final List exams; @override @@ -24,7 +25,7 @@ class RemainingExamsWidget extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - '${exam.begin.day} de ${exam.month(locale)}', + '${exam.begin.day} ${exam.month(locale)}', style: Theme.of(context).textTheme.bodyLarge, ), ExamTitle(