Skip to content

Commit

Permalink
Save ucs page semester and school year dropdown values on preferences (
Browse files Browse the repository at this point in the history
  • Loading branch information
DGoiana authored Oct 10, 2024
2 parents 08dda81 + b40045a commit ed79e99
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class PreferencesController {
static const String _favoriteRestaurants = 'favorite_restaurants';
static const String _filteredExamsTypes = 'filtered_exam_types';
static final List<String> _defaultFilteredExamTypes = Exam.displayedTypes;
static const String _semesterValue = 'semester_value';
static const String _schoolYearValue = 'school_year_value';

static final _statsToggleStreamController =
StreamController<bool>.broadcast();
Expand Down Expand Up @@ -261,4 +263,26 @@ class PreferencesController {
await prefs.setBool(_usageStatsToggleKey, value);
_statsToggleStreamController.add(value);
}

static Future<void> 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<void> setSchoolYearValue(String? value) async {
await prefs.setString(_schoolYearValue, value ?? '');
if (value == null) {
await prefs.remove(_schoolYearValue);
}
}

static String? getSchoolYearValue() {
return prefs.getString(_schoolYearValue);
}
}
7 changes: 5 additions & 2 deletions packages/uni_app/lib/view/course_units/course_units.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -23,8 +24,8 @@ class CourseUnitsPageView extends StatefulWidget {

class CourseUnitsPageViewState
extends SecondaryPageViewState<CourseUnitsPageView> {
String? selectedSchoolYear;
String? selectedSemester;
String? selectedSchoolYear = PreferencesController.getSchoolYearValue();
String? selectedSemester = PreferencesController.getSemesterValue();

@override
Widget? getHeader(BuildContext context) {
Expand Down Expand Up @@ -139,6 +140,7 @@ class CourseUnitsPageViewState
icon: const Icon(Icons.arrow_drop_down),
onChanged: (newValue) {
setState(() => selectedSemester = newValue);
PreferencesController.setSemesterValue(newValue);
},
items: availableSemesters.map<DropdownMenuItem<String>>((value) {
return DropdownMenuItem<String>(
Expand All @@ -156,6 +158,7 @@ class CourseUnitsPageViewState
icon: const Icon(Icons.arrow_drop_down),
onChanged: (newValue) {
setState(() => selectedSchoolYear = newValue);
PreferencesController.setSchoolYearValue(newValue);
},
items: availableYears.map<DropdownMenuItem<String>>((value) {
return DropdownMenuItem<String>(
Expand Down

0 comments on commit ed79e99

Please sign in to comment.