fix: review fixes

This commit is contained in:
misha
2026-11-19 11:00:41 +03:00
parent ce073b5a95
commit 29ee8ae5a8
13 changed files with 466 additions and 47 deletions

View File

@@ -22,12 +22,26 @@ class _CalendarWidgetState extends State<CalendarWidget> {
CalendarFormat _calendarFormat = CalendarFormat.week;
DateTime _focusedDay = DateTime.now();
DateTime _selectedDay = DateTime.now();
DateTime? _dayFromState(DiaryState state) {
if (state is DiaryStateLoaded) {
return state.selectedDay;
}
if (state is DiaryStateLoadedTomorrowWithDiet) {
return state.selectedDay;
}
return null;
}
@override
void initState() {
super.initState();
final selected = _dayFromState(context.read<DiaryCubit>().state);
if (widget.date != null) {
_selectedDay = widget.date!;
_focusedDay = widget.date!;
} else if (selected != null) {
_selectedDay = selected;
_focusedDay = selected;
}
}
@@ -47,9 +61,11 @@ class _CalendarWidgetState extends State<CalendarWidget> {
final daysOfWeekHeight = _scaledDaysOfWeekHeight(context);
return BlocConsumer<DiaryCubit, DiaryState>(
listener: (BuildContext context, DiaryState state) {
if (state is DiaryStateLoaded) {
final selected = _dayFromState(state);
if (selected != null) {
setState(() {
_selectedDay = state.selectedDay;
_selectedDay = selected;
_focusedDay = selected;
});
}
},
@@ -77,8 +93,12 @@ class _CalendarWidgetState extends State<CalendarWidget> {
_selectedDay = selectedDay;
_focusedDay = focusedDay;
});
final canOpenNextDay = await context.read<DiaryCubit>().setSelectedDay(selectedDay);
if (!canOpenNextDay && context.mounted) {
final cubit = context.read<DiaryCubit>();
final canOpenNextDay = await cubit.setSelectedDay(selectedDay);
if (!context.mounted || cubit.state is DiaryStateError) {
return;
}
if (!canOpenNextDay) {
showErrorDialog(context, title: s.want_to_see_tomorrow, description: s.can_not_see_next_day);
setState(() {
_selectedDay = previousSelectedDay;