From b40045a7b29d5bc00d8814743b99a57610e5af78 Mon Sep 17 00:00:00 2001 From: thePeras Date: Wed, 9 Oct 2024 22:20:42 +0100 Subject: [PATCH] Save ucs page semester and school year dropdown values on preferences --- .../local_storage/preferences_controller.dart | 24 +++++++++++++++++++ .../lib/view/course_units/course_units.dart | 7 ++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/uni_app/lib/controller/local_storage/preferences_controller.dart b/packages/uni_app/lib/controller/local_storage/preferences_controller.dart index 5c54bcef2..585f6d49c 100644 --- a/packages/uni_app/lib/controller/local_storage/preferences_controller.dart +++ b/packages/uni_app/lib/controller/local_storage/preferences_controller.dart @@ -39,6 +39,8 @@ class PreferencesController { static const String _favoriteRestaurants = 'favorite_restaurants'; static const String _filteredExamsTypes = 'filtered_exam_types'; static final List _defaultFilteredExamTypes = Exam.displayedTypes; + static const String _semesterValue = 'semester_value'; + static const String _schoolYearValue = 'school_year_value'; static final _statsToggleStreamController = StreamController.broadcast(); @@ -261,4 +263,26 @@ class PreferencesController { await prefs.setBool(_usageStatsToggleKey, value); _statsToggleStreamController.add(value); } + + static Future setSemesterValue(String? value) async { + await prefs.setString(_semesterValue, value ?? ''); + if (value == null) { + await prefs.remove(_semesterValue); + } + } + + static String? getSemesterValue() { + return prefs.getString(_semesterValue); + } + + static Future setSchoolYearValue(String? value) async { + await prefs.setString(_schoolYearValue, value ?? ''); + if (value == null) { + await prefs.remove(_schoolYearValue); + } + } + + static String? getSchoolYearValue() { + return prefs.getString(_schoolYearValue); + } } diff --git a/packages/uni_app/lib/view/course_units/course_units.dart b/packages/uni_app/lib/view/course_units/course_units.dart index 4ab198253..ee2bb0418 100644 --- a/packages/uni_app/lib/view/course_units/course_units.dart +++ b/packages/uni_app/lib/view/course_units/course_units.dart @@ -1,6 +1,7 @@ import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:uni/controller/local_storage/preferences_controller.dart'; import 'package:uni/generated/l10n.dart'; import 'package:uni/model/entities/course_units/course_unit.dart'; import 'package:uni/model/entities/profile.dart'; @@ -23,8 +24,8 @@ class CourseUnitsPageView extends StatefulWidget { class CourseUnitsPageViewState extends SecondaryPageViewState { - String? selectedSchoolYear; - String? selectedSemester; + String? selectedSchoolYear = PreferencesController.getSchoolYearValue(); + String? selectedSemester = PreferencesController.getSemesterValue(); @override Widget? getHeader(BuildContext context) { @@ -139,6 +140,7 @@ class CourseUnitsPageViewState icon: const Icon(Icons.arrow_drop_down), onChanged: (newValue) { setState(() => selectedSemester = newValue); + PreferencesController.setSemesterValue(newValue); }, items: availableSemesters.map>((value) { return DropdownMenuItem( @@ -156,6 +158,7 @@ class CourseUnitsPageViewState icon: const Icon(Icons.arrow_drop_down), onChanged: (newValue) { setState(() => selectedSchoolYear = newValue); + PreferencesController.setSchoolYearValue(newValue); }, items: availableYears.map>((value) { return DropdownMenuItem(