Skip to content

Commit

Permalink
Change the filtered exams list state globally
Browse files Browse the repository at this point in the history
  • Loading branch information
rubuy-74 committed Oct 15, 2023
1 parent d010780 commit 53da109
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions uni/lib/model/entities/exam.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Exam {
'Recurso': 'ER',
'Especial de Conclusão': 'EC',
'Port.Est.Especiais': 'EE',
'Exames ao abrigo de estatutos especiais': 'EAE'
'Exames ao abrigo de estatutos especiais': 'EAE',
};
static List<String> displayedTypes = types.keys.toList().sublist(0, 4);

Expand All @@ -56,7 +56,7 @@ class Exam {
'end': DateFormat('yyyy-MM-dd HH:mm:ss').format(end),
'rooms': rooms.join(','),
'examType': type,
'faculty': faculty
'faculty': faculty,
};
}

Expand Down
10 changes: 7 additions & 3 deletions uni/lib/view/exams/widgets/exam_filter_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import 'package:uni/model/providers/lazy/exam_provider.dart';

class ExamFilterForm extends StatefulWidget {
const ExamFilterForm(this.filteredExamsTypes, {super.key});

final Map<String, bool> filteredExamsTypes;

Map<String, bool> get filteredExamTypes =>
Map<String, bool>.from(filteredExamsTypes)
..removeWhere((key, value) => !Exam.types.containsKey(key));

@override
ExamFilterFormState createState() => ExamFilterFormState();
}
Expand All @@ -17,6 +20,8 @@ class ExamFilterFormState extends State<ExamFilterForm> {
void _changeFilteredExamList(String key, {bool? value}) {
setState(() {
widget.filteredExamsTypes[key] = value!;
Provider.of<ExamProvider>(context, listen: false)
.setFilteredExams(widget.filteredExamsTypes);
});
}

Expand Down Expand Up @@ -64,13 +69,12 @@ class FilteredExamList extends StatelessWidget {
this.context, {
super.key,
});
final void Function(String, {bool? value}) changeFilteredExamList;
final Map<String, bool> filteredExams;
final void Function(String, {bool? value}) changeFilteredExamList;
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);
Expand Down

0 comments on commit 53da109

Please sign in to comment.