improved performance and battery usage on older devices
This commit is contained in:
@@ -7,10 +7,10 @@ import '../../../../extensions/date_time.dart';
|
||||
import '../../../../state/app/modules/capabilities/bloc/capabilities_cubit.dart';
|
||||
import '../../../../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import '../../../../state/app/modules/timetable/bloc/timetable_state.dart';
|
||||
import '../../../../storage/timetable_settings.dart';
|
||||
import '../data/arbitrary_appointment.dart';
|
||||
import '../data/lesson_period_schedule.dart';
|
||||
import '../data/timetable_appointment_factory.dart';
|
||||
import '../data/timetable_name_mode.dart';
|
||||
import 'custom_workweek_calendar.dart';
|
||||
import 'special_regions_builder.dart';
|
||||
|
||||
@@ -51,9 +51,10 @@ class TimetableCalendarViewState extends State<TimetableCalendarView> {
|
||||
GlobalKey<CustomWorkWeekCalendarState>();
|
||||
|
||||
List<Appointment>? _cachedAppointments;
|
||||
// TimetableSettings and List define no `==`, so record equality degrades to
|
||||
// the same identity checks the cache always used.
|
||||
(int, TimetableSettings, List<CustomTimetableEvent>, bool)? _cacheKey;
|
||||
// Settings are keyed by the values the factory reads: the settings object is
|
||||
// re-created on every settings write, so its identity would miss the cache
|
||||
// for unrelated changes. The event list has no `==` and compares by identity.
|
||||
(int, bool, TimetableNameMode, List<CustomTimetableEvent>, bool)? _cacheKey;
|
||||
|
||||
// Stable identities let the calendar reuse its per-week pages across
|
||||
// rebuilds; rebuilding these every frame would invalidate that cache.
|
||||
@@ -71,13 +72,16 @@ class TimetableCalendarViewState extends State<TimetableCalendarView> {
|
||||
}
|
||||
|
||||
List<Appointment> _appointments(TimetableState state) {
|
||||
final timetableSettings = context
|
||||
.watch<SettingsCubit>()
|
||||
.val()
|
||||
.timetableSettings;
|
||||
final (connectDoubleLessons, nameMode) = context.select(
|
||||
(SettingsCubit c) => (
|
||||
c.state.timetableSettings.connectDoubleLessons,
|
||||
c.state.timetableSettings.timetableNameMode,
|
||||
),
|
||||
);
|
||||
final key = (
|
||||
state.dataVersion,
|
||||
timetableSettings,
|
||||
connectDoubleLessons,
|
||||
nameMode,
|
||||
widget.customEvents,
|
||||
widget.showClassInsteadOfTeacher,
|
||||
);
|
||||
@@ -91,7 +95,7 @@ class TimetableCalendarViewState extends State<TimetableCalendarView> {
|
||||
customEvents: widget.customEvents,
|
||||
subjects: state.subjects?.result ?? const [],
|
||||
holidays: state.schoolHolidays?.result ?? const [],
|
||||
settings: timetableSettings,
|
||||
settings: context.read<SettingsCubit>().val().timetableSettings,
|
||||
now: DateTime.now(),
|
||||
showClassInsteadOfTeacher: widget.showClassInsteadOfTeacher,
|
||||
).build();
|
||||
|
||||
Reference in New Issue
Block a user