From 239827bfed901fe791bad7f7651de307eedfce76 Mon Sep 17 00:00:00 2001 From: rubuy-74 Date: Wed, 5 Jul 2023 04:14:49 +0100 Subject: [PATCH] Refactoring exams page files --- uni/lib/view/exams/exams.dart | 51 ++++++++----------- .../view/exams/widgets/exam_filter_form.dart | 31 ++++++----- 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/uni/lib/view/exams/exams.dart b/uni/lib/view/exams/exams.dart index 59bda1785..318bba4d8 100644 --- a/uni/lib/view/exams/exams.dart +++ b/uni/lib/view/exams/exams.dart @@ -102,35 +102,28 @@ class ExamsPageViewState extends GeneralPageViewState { key: Key(keyValue), margin: const EdgeInsets.only(bottom: 8), padding: const EdgeInsets.all(8), - child: createExamsCards(context, exams), - ); - } - - Widget createExamsCards(BuildContext context, List exams) { - final examCards = [ - DayTitle( - day: exams[0].begin.day.toString(), - weekDay: exams[0].weekDay, - month: exams[0].month, - ), - ]; - for (var i = 0; i < exams.length; i++) { - examCards.add(createExamContext(context, exams[i])); - } - return Column(children: examCards); - } - - Widget createExamContext(BuildContext context, Exam exam) { - final isHidden = - Provider.of(context).hiddenExams.contains(exam.id); - return Container( - key: Key('$exam-exam'), - margin: const EdgeInsets.fromLTRB(12, 4, 12, 0), - child: RowContainer( - color: isHidden - ? Theme.of(context).hintColor - : Theme.of(context).scaffoldBackgroundColor, - child: ExamRow(exam: exam, teacher: '', mainPage: false), + child: Column( + children: [ + DayTitle( + day: exams[0].begin.day.toString(), + weekDay: exams[0].weekDay, + month: exams[0].month, + ), + ...exams.map( + (exam) => Container( + key: Key('$exam-exam'), + margin: const EdgeInsets.fromLTRB(12, 4, 12, 0), + child: RowContainer( + color: Provider.of(context) + .hiddenExams + .contains(exam.id) + ? Theme.of(context).hintColor + : Theme.of(context).scaffoldBackgroundColor, + child: ExamRow(exam: exam, teacher: '', mainPage: false), + ), + ), + ), + ], ), ); } diff --git a/uni/lib/view/exams/widgets/exam_filter_form.dart b/uni/lib/view/exams/widgets/exam_filter_form.dart index 91a1483aa..74f072191 100644 --- a/uni/lib/view/exams/widgets/exam_filter_form.dart +++ b/uni/lib/view/exams/widgets/exam_filter_form.dart @@ -37,21 +37,24 @@ class ExamFilterFormState extends State { content: SizedBox( height: 230, width: 200, - child: getExamCheckboxes(widget.filteredExamsTypes, context), + child: FilteredExamList(widget.filteredExamsTypes, context), ), ); } +} - Widget getExamCheckboxes( - Map filteredExams, - BuildContext context, - ) { +class FilteredExamList extends StatelessWidget { + const FilteredExamList(this.filteredExams, this.context, {super.key}); + final Map filteredExams; + final BuildContext context; + @override + Widget build(BuildContext context) { filteredExams.removeWhere((key, value) => !Exam.types.containsKey(key)); return ListView( - children: List.generate(filteredExams.length, (i) { - final key = filteredExams.keys.elementAt(i); - if (!Exam.types.containsKey(key)) return const Text(''); - return CheckboxListTile( + children: List.generate(filteredExams.length, (i) { + final key = filteredExams.keys.elementAt(i); + if (!Exam.types.containsKey(key)) return const Text(''); + return CheckboxListTile( contentPadding: EdgeInsets.zero, title: Text( key, @@ -62,12 +65,8 @@ class ExamFilterFormState extends State { key: Key('ExamCheck$key'), value: filteredExams[key], onChanged: (value) { - setState(() { - filteredExams[key] = value!; - }); - }, - ); - }), - ); + filteredExams[key] = value!; + }); + })); } }