Skip to content

Commit

Permalink
Refactoring exams page files
Browse files Browse the repository at this point in the history
  • Loading branch information
rubuy-74 authored and bdmendes committed Aug 24, 2023
1 parent b03270d commit 239827b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 45 deletions.
51 changes: 22 additions & 29 deletions uni/lib/view/exams/exams.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,28 @@ class ExamsPageViewState extends GeneralPageViewState<ExamsPageView> {
key: Key(keyValue),
margin: const EdgeInsets.only(bottom: 8),
padding: const EdgeInsets.all(8),
child: createExamsCards(context, exams),
);
}

Widget createExamsCards(BuildContext context, List<Exam> exams) {
final examCards = <Widget>[
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<ExamProvider>(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<ExamProvider>(context)
.hiddenExams
.contains(exam.id)
? Theme.of(context).hintColor
: Theme.of(context).scaffoldBackgroundColor,
child: ExamRow(exam: exam, teacher: '', mainPage: false),
),
),
),
],
),
);
}
Expand Down
31 changes: 15 additions & 16 deletions uni/lib/view/exams/widgets/exam_filter_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@ class ExamFilterFormState extends State<ExamFilterForm> {
content: SizedBox(
height: 230,
width: 200,
child: getExamCheckboxes(widget.filteredExamsTypes, context),
child: FilteredExamList(widget.filteredExamsTypes, context),
),
);
}
}

Widget getExamCheckboxes(
Map<String, bool> filteredExams,
BuildContext context,
) {
class FilteredExamList extends StatelessWidget {
const FilteredExamList(this.filteredExams, this.context, {super.key});
final Map<String, bool> 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,
Expand All @@ -62,12 +65,8 @@ class ExamFilterFormState extends State<ExamFilterForm> {
key: Key('ExamCheck$key'),
value: filteredExams[key],
onChanged: (value) {
setState(() {
filteredExams[key] = value!;
});
},
);
}),
);
filteredExams[key] = value!;
});
}));
}
}

0 comments on commit 239827b

Please sign in to comment.