diff --git a/lib/features/diary/presentation/pages/diary_screen.dart b/lib/features/diary/presentation/pages/diary_screen.dart index 00c73b02..74b6cfb1 100644 --- a/lib/features/diary/presentation/pages/diary_screen.dart +++ b/lib/features/diary/presentation/pages/diary_screen.dart @@ -122,7 +122,10 @@ class _DiaryScreenContentState extends State { centerTitle: true, ), body: SingleChildScrollView( - padding: const EdgeInsets.only(bottom: 16, top: 8), + padding: EdgeInsets.only( + bottom: 16, + top: widget.diaryId == null ? 0 : 8, + ), physics: const BouncingScrollPhysics(), child: Column( children: [ @@ -133,7 +136,12 @@ class _DiaryScreenContentState extends State { ], if (state is DiaryStateLoaded && _canShowInsights(state)) Padding( - padding: const EdgeInsets.fromLTRB(4, 12, 4, 12), + padding: EdgeInsets.fromLTRB( + 4, + widget.diaryId == null ? 0 : 12, + 4, + 12, + ), child: _DiaryInsights( slug: state.isConsultantView ? _ownerSlug(state) : null, canAdd: !state.isConsultantView, @@ -325,6 +333,7 @@ class _DiaryInsightsState extends State<_DiaryInsights> { canAdd: widget.canAdd, refreshToken: _refreshToken, initialIntraDate: widget.diaryDate, + showShadow: false, ), ); } diff --git a/lib/features/diary/presentation/widgets/calendar_widget.dart b/lib/features/diary/presentation/widgets/calendar_widget.dart index 3b386d67..0e27f7db 100644 --- a/lib/features/diary/presentation/widgets/calendar_widget.dart +++ b/lib/features/diary/presentation/widgets/calendar_widget.dart @@ -3,8 +3,10 @@ import 'package:eatvio_app/core/widgets/show_error_dialog.dart'; import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart'; import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart'; import 'package:eatvio_app/generated/l10n.dart'; -import 'package:material_ui/material_ui.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:intl/intl.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:table_calendar/table_calendar.dart'; class CalendarWidget extends StatefulWidget { @@ -15,13 +17,21 @@ class CalendarWidget extends StatefulWidget { State createState() => _CalendarWidgetState(); } -class _CalendarWidgetState extends State { +class _CalendarWidgetState extends State + with SingleTickerProviderStateMixin { + static const _locale = 'ru_RU'; static const _kDaysOfWeekHeight = 16.0; static const _kRowHeight = 52.0; + static const _dayCellMargin = 6.0; + static const _dragHandlePadding = 5.0; - CalendarFormat _calendarFormat = CalendarFormat.week; + late final _expansion = AnimationController( + vsync: this, + duration: const Duration(milliseconds: 180), + ); DateTime _focusedDay = DateTime.now(); DateTime _selectedDay = DateTime.now(); + DateTime? _dayFromState(DiaryState state) { if (state is DiaryStateLoaded) { return state.selectedDay; @@ -35,11 +45,9 @@ class _CalendarWidgetState extends State { @override void initState() { super.initState(); - final selected = _dayFromState(context.read().state); - if (widget.date != null) { - _selectedDay = widget.date!; - _focusedDay = widget.date!; - } else if (selected != null) { + final selected = + widget.date ?? _dayFromState(context.read().state); + if (selected != null) { _selectedDay = selected; _focusedDay = selected; } @@ -54,13 +62,30 @@ class _CalendarWidgetState extends State { } } + @override + void dispose() { + _expansion.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { - final s = S.of(context); - final textScaler = MediaQuery.textScalerOf(context); - final daysOfWeekHeight = _scaledDaysOfWeekHeight(context); - return BlocConsumer( - listener: (BuildContext context, DiaryState state) { + final rowHeight = MediaQuery.textScalerOf(context).scale(_kRowHeight); + final firstOfMonth = DateTime.utc(_focusedDay.year, _focusedDay.month); + final daysInMonth = DateTime.utc( + _focusedDay.year, + _focusedDay.month + 1, + 0, + ).day; + final daysBeforeMonth = firstOfMonth.weekday - DateTime.monday; + final weekCount = (daysBeforeMonth + daysInMonth + 6) ~/ 7; + final focusedWeek = (daysBeforeMonth + _focusedDay.day - 1) ~/ 7; + final extraHeight = (weekCount - 1) * rowHeight; + final week = _buildDays(rowHeight, CalendarFormat.week); + final month = _buildDays(rowHeight, CalendarFormat.month); + + return BlocListener( + listener: (context, state) { final selected = _dayFromState(state); if (selected != null) { setState(() { @@ -69,80 +94,167 @@ class _CalendarWidgetState extends State { }); } }, - builder: (BuildContext context, DiaryState state) { - return Column( - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: const EdgeInsets.only(top: 16), - child: TableCalendar( - focusedDay: _focusedDay, - firstDay: DateTime.utc(2020, 10, 16), - lastDay: DateTime.utc(2030, 3, 14), - locale: 'ru_RU', - startingDayOfWeek: StartingDayOfWeek.monday, - calendarFormat: _calendarFormat, - daysOfWeekHeight: daysOfWeekHeight, - rowHeight: textScaler.scale(_kRowHeight), - headerStyle: const HeaderStyle(titleCentered: true, formatButtonVisible: false, leftChevronVisible: false, rightChevronVisible: false), - onDaySelected: (selectedDay, focusedDay) async { - if (!isSameDay(_selectedDay, selectedDay)) { - final previousSelectedDay = _selectedDay; - final previousFocusedDay = _selectedDay; - setState(() { - _selectedDay = selectedDay; - _focusedDay = focusedDay; - }); - final cubit = context.read(); - 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; - _focusedDay = previousFocusedDay; - }); - return; - } - } - }, - selectedDayPredicate: (day) { - return isSameDay(_selectedDay, day); - }, - onPageChanged: (focusedDay) { - setState(() { - _focusedDay = focusedDay; - }); - }, - onFormatChanged: (format) { - if (_calendarFormat != format) { - setState(() { - _calendarFormat = format; - }); - } - }, - calendarStyle: CalendarStyle( - weekendDecoration: const BoxDecoration(color: Colors.white, shape: BoxShape.circle), - defaultDecoration: const BoxDecoration(color: Colors.white, shape: BoxShape.circle), - selectedDecoration: BoxDecoration(color: appTheme.blueA400, shape: BoxShape.circle), - todayTextStyle: const TextStyle(color: Colors.black), - todayDecoration: BoxDecoration( - border: Border.all(color: appTheme.blueA400, width: 2), - color: Colors.white, - shape: BoxShape.circle, + child: Padding( + padding: const EdgeInsets.only(top: 4), + child: AnimatedBuilder( + animation: _expansion, + child: _buildWeekdays(context), + builder: (context, weekdays) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + _buildHeader(context), + weekdays!, + ClipRect( + child: SizedBox( + height: rowHeight + extraHeight * _expansion.value, + child: OverflowBox( + // При раскрытии показываем строки вокруг открытой недели. + alignment: Alignment( + 0, + 2 * focusedWeek / (weekCount - 1) - 1, + ), + minHeight: 0, + maxHeight: double.infinity, + child: _expansion.value == 0 ? week : month, + ), ), ), - ), - ), - _arrowDown(), - ], - ); - }, + _buildDragHandle(extraHeight), + ], + ); + }, + ), + ), ); } + Widget _buildHeader(BuildContext context) { + final s = S.of(context); + final expanded = _expansion.value >= 0.5; + final label = DateFormat.yMMMM(_locale).format(_focusedDay); + + return Tooltip( + message: expanded ? s.hide : s.expand, + child: InkWell( + onTap: () => _expansion.value = expanded ? 0 : 1, + borderRadius: BorderRadius.circular(8), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text(label, style: const HeaderStyle().titleTextStyle), + const SizedBox(width: 4), + Icon( + expanded + ? Icons.keyboard_arrow_up_rounded + : Icons.keyboard_arrow_down_rounded, + size: 18, + color: appTheme.blueA400, + ), + ], + ), + ), + ), + ); + } + + Widget _buildWeekdays(BuildContext context) { + const style = DaysOfWeekStyle(); + final format = DateFormat.E(_locale); + + return ExcludeSemantics( + child: SizedBox( + height: _scaledDaysOfWeekHeight(context), + child: Row( + children: List.generate(DateTime.daysPerWeek, (index) { + final day = DateTime.utc( + _focusedDay.year, + _focusedDay.month, + _focusedDay.day - _focusedDay.weekday + DateTime.monday + index, + ); + return Expanded( + child: Center( + child: Text( + format.format(day), + style: day.weekday >= DateTime.saturday + ? style.weekendStyle + : style.weekdayStyle, + ), + ), + ); + }), + ), + ), + ); + } + + Widget _buildDays(double rowHeight, CalendarFormat format) { + return TableCalendar( + key: ValueKey(format), + focusedDay: _focusedDay, + firstDay: DateTime.utc(2020, 10, 16), + lastDay: DateTime.utc(2030, 3, 14), + locale: _locale, + startingDayOfWeek: StartingDayOfWeek.monday, + calendarFormat: format, + availableGestures: AvailableGestures.horizontalSwipe, + headerVisible: false, + daysOfWeekVisible: false, + rowHeight: rowHeight, + onDaySelected: _selectDay, + selectedDayPredicate: (day) => isSameDay(_selectedDay, day), + onPageChanged: (focusedDay) => setState(() => _focusedDay = focusedDay), + calendarStyle: CalendarStyle( + cellMargin: const EdgeInsets.all(_dayCellMargin), + weekendDecoration: const BoxDecoration( + color: Colors.white, + shape: BoxShape.circle, + ), + defaultDecoration: const BoxDecoration( + color: Colors.white, + shape: BoxShape.circle, + ), + selectedDecoration: BoxDecoration( + color: appTheme.blueA400, + shape: BoxShape.circle, + ), + todayTextStyle: const TextStyle(color: Colors.black), + todayDecoration: BoxDecoration( + border: Border.all(color: appTheme.blueA400, width: 2), + color: Colors.white, + shape: BoxShape.circle, + ), + ), + ); + } + + Future _selectDay(DateTime selectedDay, DateTime focusedDay) async { + if (isSameDay(_selectedDay, selectedDay)) return; + + final previousSelectedDay = _selectedDay; + final previousFocusedDay = _focusedDay; + setState(() { + _selectedDay = selectedDay; + _focusedDay = focusedDay; + }); + final cubit = context.read(); + final canOpenNextDay = await cubit.setSelectedDay(selectedDay); + if (!mounted || cubit.state is DiaryStateError || canOpenNextDay) return; + + final s = S.of(context); + showErrorDialog( + context, + title: s.want_to_see_tomorrow, + description: s.can_not_see_next_day, + ); + setState(() { + _selectedDay = previousSelectedDay; + _focusedDay = previousFocusedDay; + }); + } + double _scaledDaysOfWeekHeight(BuildContext context) { final painter = TextPainter( text: TextSpan(text: 'Щy', style: DefaultTextStyle.of(context).style), @@ -155,26 +267,44 @@ class _CalendarWidgetState extends State { return height.clamp(_kDaysOfWeekHeight, double.infinity); } - void _nextCalendarFormat() { - setState(() { - _calendarFormat = CalendarFormat.values[(_calendarFormat.index - 1) % CalendarFormat.values.length]; - }); - } - - GestureDetector _arrowDown() { + Widget _buildDragHandle(double extraHeight) { return GestureDetector( - behavior: HitTestBehavior.translucent, - onVerticalDragStart: (_) { - _nextCalendarFormat(); + behavior: HitTestBehavior.opaque, + dragStartBehavior: DragStartBehavior.down, + onVerticalDragStart: (_) => _expansion.stop(), + onVerticalDragUpdate: (details) { + _expansion.value = (_expansion.value + details.delta.dy / extraHeight) + .clamp(0.0, 1.0); }, - onTap: () { - _nextCalendarFormat(); - }, - child: Container( + onVerticalDragEnd: (details) => + _settleExpansion(details.velocity.pixelsPerSecond.dy), + onVerticalDragCancel: _settleExpansion, + child: SizedBox( width: double.infinity, - padding: const EdgeInsets.only(top: 8, bottom: 16), - child: Icon(_calendarFormat == CalendarFormat.month ? Icons.keyboard_arrow_up_rounded : Icons.keyboard_arrow_down_rounded, color: Colors.grey.shade600), + child: Padding( + // Отступ ячеек уже добавляет место над полоской. + padding: const EdgeInsets.only( + top: _dragHandlePadding, + bottom: _dragHandlePadding + _dayCellMargin, + ), + child: Center( + child: DecoratedBox( + decoration: BoxDecoration( + color: appTheme.blueA400, + borderRadius: BorderRadius.circular(2), + ), + child: const SizedBox(width: 28, height: 4), + ), + ), + ), ), ); } + + void _settleExpansion([double velocity = 0]) { + final shouldExpand = velocity.abs() >= 400 + ? velocity > 0 + : _expansion.value >= 0.5; + _expansion.animateTo(shouldExpand ? 1 : 0, curve: Curves.easeOutCubic); + } } diff --git a/lib/features/feed/presentation/widgets/plan_widget.dart b/lib/features/feed/presentation/widgets/plan_widget.dart index b5ad3bee..e306312a 100644 --- a/lib/features/feed/presentation/widgets/plan_widget.dart +++ b/lib/features/feed/presentation/widgets/plan_widget.dart @@ -22,6 +22,7 @@ import 'package:share_plus/share_plus.dart'; class PlanWidget extends StatefulWidget { final PlanModel plan; final int index; + final bool showPriceOnCover; final Future Function(String slug)? onLikeTap; final Future Function(String slug, bool isFavorite)? onToggleFavorite; final VoidCallback? onPlanChanged; @@ -30,6 +31,7 @@ class PlanWidget extends StatefulWidget { super.key, required this.plan, required this.index, + this.showPriceOnCover = false, this.onLikeTap, this.onToggleFavorite, this.onPlanChanged, @@ -45,6 +47,10 @@ class _PlanWidgetState extends State { @override Widget build(BuildContext context) { final s = S.of(context); + final minPrice = widget.plan.minPriceOfOptions.toStringAsFixed(0); + final price = widget.plan.packetsCount == 1 + ? '${widget.plan.packet1Options?.price ?? minPrice}₽' + : '${s.from} $minPrice₽'; return InkWell( onTap: () => GoRouter.of(context).pushNamed( 'aboutPlanScreen', @@ -119,14 +125,40 @@ class _PlanWidgetState extends State { ), Positioned( bottom: 16, - child: SizedBox( - width: MediaQuery.sizeOf(context).width, - child: InfoRow( - plan: widget.plan, - itemsBackgroundColor: appTheme.whiteA700, - disableDescriptionOfTypes: true, - type: ProductType.plan, - ), + left: 0, + right: 0, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (widget.showPriceOnCover) + Padding( + padding: const EdgeInsets.only(bottom: 8), + child: Container( + padding: const EdgeInsets.symmetric( + horizontal: 14, + vertical: 4, + ), + decoration: BoxDecoration( + color: appTheme.greenA700, + borderRadius: const BorderRadius.horizontal( + right: Radius.circular(8), + ), + ), + child: Text( + price, + style: TextStyles.textSSemibold.copyWith( + color: appTheme.whiteA700, + ), + ), + ), + ), + InfoRow( + plan: widget.plan, + itemsBackgroundColor: appTheme.whiteA700, + disableDescriptionOfTypes: true, + type: ProductType.plan, + ), + ], ), ), ], @@ -221,14 +253,16 @@ class _PlanWidgetState extends State { ), ], ), - const Spacer(), - Text( - '${widget.plan.packetsCount == 1 ? widget.plan.packet1Options?.price : '${s.from} ${widget.plan.minPriceOfOptions.toStringAsFixed(0)}'}₽', - style: TextStyles.headingXLSemibold.copyWith( - color: appTheme.greenA700, + if (!widget.showPriceOnCover) ...[ + const Spacer(), + Text( + price, + style: TextStyles.headingXLSemibold.copyWith( + color: appTheme.greenA700, + ), ), - ), - const SizedBox(width: 16), + const SizedBox(width: 16), + ], ], ), title: Padding( diff --git a/lib/features/insights/presentation/widgets/insights_card.dart b/lib/features/insights/presentation/widgets/insights_card.dart index 9432221f..4abc3a3b 100644 --- a/lib/features/insights/presentation/widgets/insights_card.dart +++ b/lib/features/insights/presentation/widgets/insights_card.dart @@ -39,12 +39,14 @@ class InsightsCard extends StatelessWidget { this.kbjuEnabled = InsightsFeatureFlags.kbjuEnabled, this.refreshToken = 0, this.initialIntraDate, + this.showShadow = true, }); final String? slug; final bool canAdd; final InsightsRepository? repository; final bool kbjuEnabled; + final bool showShadow; /// При смене значения блок перезапрашивает данные (например, после правок /// в дневнике), сохраняя вкладку, период и выбранный день. @@ -68,6 +70,7 @@ class InsightsCard extends StatelessWidget { child: _InsightsView( refreshToken: refreshToken, initialIntraDate: initialIntraDate, + showShadow: showShadow, ), ), ); @@ -78,10 +81,12 @@ class _InsightsView extends StatefulWidget { const _InsightsView({ required this.refreshToken, required this.initialIntraDate, + required this.showShadow, }); final int refreshToken; final String? initialIntraDate; + final bool showShadow; @override State<_InsightsView> createState() => _InsightsViewState(); @@ -112,9 +117,13 @@ class _InsightsViewState extends State<_InsightsView> { builder: (context, state) { return switch (state) { InsightsStateLoaded() => _CardShell( + showShadow: widget.showShadow, child: _LoadedContent(state: state), ), - InsightsStateError() => const _CardShell(child: _ErrorContent()), + InsightsStateError() => _CardShell( + showShadow: widget.showShadow, + child: const _ErrorContent(), + ), _ => const SizedBox.shrink(), }; }, @@ -123,9 +132,10 @@ class _InsightsViewState extends State<_InsightsView> { } class _CardShell extends StatelessWidget { - const _CardShell({required this.child}); + const _CardShell({required this.child, required this.showShadow}); final Widget child; + final bool showShadow; @override Widget build(BuildContext context) { @@ -135,12 +145,13 @@ class _CardShell extends StatelessWidget { decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(8), - boxShadow: const [ - BoxShadow( - color: InsightsColors.cardShadow, - blurRadius: 4, - offset: Offset(0, 2), - ), + boxShadow: [ + if (showShadow) + const BoxShadow( + color: InsightsColors.cardShadow, + blurRadius: 4, + offset: Offset(0, 2), + ), ], ), child: child, diff --git a/lib/features/profile/presentation/pages/profile_screen.dart b/lib/features/profile/presentation/pages/profile_screen.dart index d64421f2..2c89261b 100644 --- a/lib/features/profile/presentation/pages/profile_screen.dart +++ b/lib/features/profile/presentation/pages/profile_screen.dart @@ -494,6 +494,7 @@ class _ProfileScreenState extends State { return PlanWidget( plan: state.plansList[index], index: index, + showPriceOnCover: true, onLikeTap: (slug) => plansCubit.likePlan(slug), onToggleFavorite: (slug, isFavorite) => isFavorite ? plansCubit.removePlanFromFavorite(slug) diff --git a/test/features/diary/presentation/widgets/calendar_widget_smoke_test.dart b/test/features/diary/presentation/widgets/calendar_widget_smoke_test.dart index 874d2a29..501b4f38 100644 --- a/test/features/diary/presentation/widgets/calendar_widget_smoke_test.dart +++ b/test/features/diary/presentation/widgets/calendar_widget_smoke_test.dart @@ -8,6 +8,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:intl/date_symbol_data_local.dart'; +import 'package:intl/intl.dart'; import 'package:table_calendar/table_calendar.dart'; class FakeDiaryCubit extends Cubit implements DiaryCubit { @@ -28,15 +29,20 @@ void main() { theme: ThemeHelper().themeData(), builder: (context, appChild) { return MediaQuery( - data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(textScale)), + data: MediaQuery.of( + context, + ).copyWith(textScaler: TextScaler.linear(textScale)), child: appChild!, ); }, - localizationsDelegates: const [S.delegate, ...GlobalMaterialLocalizations.delegates], + localizationsDelegates: const [ + S.delegate, + ...GlobalMaterialLocalizations.delegates, + ], supportedLocales: const [Locale('ru')], home: BlocProvider.value( value: cubit, - child: Scaffold(body: child), + child: Scaffold(body: SingleChildScrollView(child: child)), ), ); } @@ -52,19 +58,124 @@ void main() { testWidgets('scales weekday row when system font is large', (tester) async { const textScale = 2.0; final cubit = FakeDiaryCubit(const DiaryState.loading()); - await tester.pumpWidget(wrap(const CalendarWidget(), cubit, textScale: textScale)); + await tester.pumpWidget( + wrap(const CalendarWidget(), cubit, textScale: textScale), + ); await tester.pump(); - final calendar = tester.widget>(find.byType(TableCalendar)); - expect(calendar.daysOfWeekHeight, greaterThan(16 * textScale * 0.9)); + final calendar = tester.widget>( + find.byType(TableCalendar), + ); expect(calendar.rowHeight, 52 * textScale); expect(find.text('пн'), findsWidgets); - final weekday = tester.renderObject(find.text('пн').first); - expect(weekday.size.height, lessThanOrEqualTo(calendar.daysOfWeekHeight + 0.5)); + final weekday = tester.renderObject( + find.text('пн').first, + ); + expect(weekday.size.height, greaterThan(16 * textScale * 0.9)); + expect( + tester.getBottomLeft(find.text('пн')).dy, + lessThanOrEqualTo( + tester.getTopLeft(find.byType(TableCalendar)).dy, + ), + ); expect(tester.takeException(), isNull); await cubit.close(); }); + + testWidgets( + 'header chevron switches directly between the focused week and month', + (tester) async { + final cubit = FakeDiaryCubit(const DiaryState.loading()); + addTearDown(cubit.close); + final widget = find.byType(CalendarWidget); + final date = DateTime(2026, 11, 23); + await tester.pumpWidget(wrap(CalendarWidget(date: date), cubit)); + await tester.pumpAndSettle(); + + final header = find.text(DateFormat.yMMMM('ru_RU').format(date)); + final weekHeight = tester.getSize(widget).height; + expect(find.text('23').hitTestable(), findsOneWidget); + expect(find.text('9').hitTestable(), findsNothing); + + await tester.tap(find.byIcon(Icons.keyboard_arrow_down_rounded)); + await tester.pump(); + expect(header, findsOneWidget); + expect(tester.getSize(widget).height, weekHeight + 5 * 52); + expect(find.text('9').hitTestable(), findsOneWidget); + expect(find.text('23').hitTestable(), findsOneWidget); + + await tester.tap(find.byIcon(Icons.keyboard_arrow_up_rounded)); + await tester.pump(); + expect(tester.getSize(widget).height, weekHeight); + expect(find.text('23').hitTestable(), findsOneWidget); + }, + ); + + testWidgets('horizontal swipes still page by week and by month', ( + tester, + ) async { + final cubit = FakeDiaryCubit(const DiaryState.loading()); + addTearDown(cubit.close); + await tester.pumpWidget( + wrap(CalendarWidget(date: DateTime(2026, 11, 23)), cubit), + ); + await tester.pumpAndSettle(); + + final days = find.byType(TableCalendar); + await tester.fling(days, const Offset(-450, 0), 1000); + await tester.pumpAndSettle(); + expect(find.text('30').hitTestable(), findsOneWidget); + expect(find.text('23').hitTestable(), findsNothing); + + await tester.tap(find.byIcon(Icons.keyboard_arrow_down_rounded)); + await tester.pump(); + await tester.fling(days, const Offset(-450, 0), 1000); + await tester.pumpAndSettle(); + expect( + find.text(DateFormat.yMMMM('ru_RU').format(DateTime(2026, 12))), + findsOneWidget, + ); + }); + + testWidgets( + 'dragging the bottom handle resizes the calendar before release', + (tester) async { + final cubit = FakeDiaryCubit(const DiaryState.loading()); + addTearDown(cubit.close); + final widget = find.byType(CalendarWidget); + await tester.pumpWidget( + wrap(CalendarWidget(date: DateTime(2026, 11, 23)), cubit), + ); + await tester.pumpAndSettle(); + + final weekBottom = tester.getBottomLeft(widget).dy; + final centerX = tester.getCenter(widget).dx; + final drag = await tester.startGesture( + Offset(centerX, weekBottom - 12), + ); + await drag.moveBy(const Offset(0, 64)); + await tester.pump(); + expect(tester.getBottomLeft(widget).dy, closeTo(weekBottom + 64, 1)); + expect(find.text('23').hitTestable(), findsOneWidget); + + await drag.moveBy(const Offset(0, 100)); + await drag.up(); + await tester.pumpAndSettle(); + final monthBottom = weekBottom + 5 * 52; + expect(tester.getBottomLeft(widget).dy, closeTo(monthBottom, 1)); + + final reverse = await tester.startGesture( + Offset(centerX, monthBottom - 12), + ); + await reverse.moveBy(const Offset(0, -160)); + await tester.pump(); + expect(tester.getBottomLeft(widget).dy, closeTo(monthBottom - 160, 1)); + await reverse.up(); + await tester.pumpAndSettle(); + expect(tester.getBottomLeft(widget).dy, closeTo(weekBottom, 1)); + }, + ); }); }