Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/exams page #818

Closed
wants to merge 9 commits into from
2 changes: 1 addition & 1 deletion uni/lib/view/exams/exams.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ExamsPageViewState extends GeneralPageViewState<ExamsPageView> {
Column(
children:
createExamsColumn(context, examProvider.getFilteredExams()),
)
),
],
);
},
Expand Down
38 changes: 27 additions & 11 deletions uni/lib/view/exams/widgets/exam_filter_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class ExamFilterForm extends StatefulWidget {
}

class ExamFilterFormState extends State<ExamFilterForm> {
void _changeFilteredExamList(String key, {bool? value}) {
setState(() {
widget.filteredExamsTypes[key] = value!;
});
}

@override
Widget build(BuildContext context) {
return AlertDialog(
Expand All @@ -36,20 +42,34 @@ class ExamFilterFormState extends State<ExamFilterForm> {
.setFilteredExams(widget.filteredExamsTypes);
Navigator.pop(context);
},
)
),
],
content: SizedBox(
height: 230,
width: 200,
child: getExamCheckboxes(widget.filteredExamsTypes, context),
child: FilteredExamList(
widget.filteredExamsTypes,
_changeFilteredExamList,
context,
),
),
);
}
}

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