Skip to content

Commit

Permalink
✨ Cache the displayDate
Browse files Browse the repository at this point in the history
  • Loading branch information
H2Sxxa committed Aug 23, 2024
1 parent f42ebfc commit d14ad9e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/models/translators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ var calendarViewTr = StringTranslator(
[CalendarView.week, CalendarView.day, CalendarView.schedule])
.translate(CalendarView.day, "天")
.translate(CalendarView.week, "星期")
.translate(CalendarView.workWeek, "星期简略")
.translate(CalendarView.workWeek, "星期缩略")
.translate(CalendarView.schedule, "日程");
16 changes: 14 additions & 2 deletions lib/views/pages/calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class CalendarHeader extends StatefulWidget {
State<StatefulWidget> createState() => CalendarHeaderState();
}

/// Cache the `displayDate` here
DateTime? _displayDate;

class CalendarHeaderState extends State<CalendarHeader> {
CalendarController get controller => widget.controller;

Expand All @@ -45,6 +48,11 @@ class CalendarHeaderState extends State<CalendarHeader> {
}

void _listener(String data) {
// Store the cache
if (data == "displayDate") {
_displayDate = controller.displayDate;
}

setState(() {});
}

Expand All @@ -59,7 +67,7 @@ class CalendarHeaderState extends State<CalendarHeader> {
Widget build(BuildContext context) {
var formatter = DateFormat.yMMM(
Localizations.localeOf(viewKey.currentContext!).languageCode);
var date = controller.displayDate ?? DateTime.now();
var date = _displayDate ?? controller.displayDate ?? DateTime.now();
ApplicationConfigs configs = ArcheBus().of();
var isWide = isWideScreen(context);
var colorScheme = Theme.of(context).colorScheme;
Expand Down Expand Up @@ -257,6 +265,7 @@ class CurriculumPageState extends State<CurriculumPage>

var calendar = SfCalendar(
controller: calendarController,
initialDisplayDate: _displayDate,
view: view,
firstDayOfWeek: 1,
headerHeight: 0,
Expand Down Expand Up @@ -410,7 +419,10 @@ class CurriculumPageState extends State<CurriculumPage>
dataSource: CurriculumDataSource(snapshot.data!.get().data),
);

return buildHeader(calendarController, calendar);
return buildHeader(
calendarController,
calendar,
);
},
);
}
Expand Down

0 comments on commit d14ad9e

Please sign in to comment.