forked from eatvio/eatvio_app
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65219bce77 | ||
|
|
ad122ed2f7 |
@@ -122,7 +122,10 @@ class _DiaryScreenContentState extends State<DiaryScreenContent> {
|
|||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
),
|
),
|
||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
padding: const EdgeInsets.only(bottom: 16, top: 8),
|
padding: EdgeInsets.only(
|
||||||
|
bottom: 16,
|
||||||
|
top: widget.diaryId == null ? 0 : 8,
|
||||||
|
),
|
||||||
physics: const BouncingScrollPhysics(),
|
physics: const BouncingScrollPhysics(),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -133,7 +136,12 @@ class _DiaryScreenContentState extends State<DiaryScreenContent> {
|
|||||||
],
|
],
|
||||||
if (state is DiaryStateLoaded && _canShowInsights(state))
|
if (state is DiaryStateLoaded && _canShowInsights(state))
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(4, 12, 4, 12),
|
padding: EdgeInsets.fromLTRB(
|
||||||
|
4,
|
||||||
|
widget.diaryId == null ? 0 : 12,
|
||||||
|
4,
|
||||||
|
12,
|
||||||
|
),
|
||||||
child: _DiaryInsights(
|
child: _DiaryInsights(
|
||||||
slug: state.isConsultantView ? _ownerSlug(state) : null,
|
slug: state.isConsultantView ? _ownerSlug(state) : null,
|
||||||
canAdd: !state.isConsultantView,
|
canAdd: !state.isConsultantView,
|
||||||
@@ -325,6 +333,7 @@ class _DiaryInsightsState extends State<_DiaryInsights> {
|
|||||||
canAdd: widget.canAdd,
|
canAdd: widget.canAdd,
|
||||||
refreshToken: _refreshToken,
|
refreshToken: _refreshToken,
|
||||||
initialIntraDate: widget.diaryDate,
|
initialIntraDate: widget.diaryDate,
|
||||||
|
showShadow: false,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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_cubit.dart';
|
||||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
|
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
|
||||||
import 'package:eatvio_app/generated/l10n.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:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:table_calendar/table_calendar.dart';
|
import 'package:table_calendar/table_calendar.dart';
|
||||||
|
|
||||||
class CalendarWidget extends StatefulWidget {
|
class CalendarWidget extends StatefulWidget {
|
||||||
@@ -15,13 +17,21 @@ class CalendarWidget extends StatefulWidget {
|
|||||||
State<CalendarWidget> createState() => _CalendarWidgetState();
|
State<CalendarWidget> createState() => _CalendarWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CalendarWidgetState extends State<CalendarWidget> {
|
class _CalendarWidgetState extends State<CalendarWidget>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
|
static const _locale = 'ru_RU';
|
||||||
static const _kDaysOfWeekHeight = 16.0;
|
static const _kDaysOfWeekHeight = 16.0;
|
||||||
static const _kRowHeight = 52.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 _focusedDay = DateTime.now();
|
||||||
DateTime _selectedDay = DateTime.now();
|
DateTime _selectedDay = DateTime.now();
|
||||||
|
|
||||||
DateTime? _dayFromState(DiaryState state) {
|
DateTime? _dayFromState(DiaryState state) {
|
||||||
if (state is DiaryStateLoaded) {
|
if (state is DiaryStateLoaded) {
|
||||||
return state.selectedDay;
|
return state.selectedDay;
|
||||||
@@ -35,11 +45,9 @@ class _CalendarWidgetState extends State<CalendarWidget> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
final selected = _dayFromState(context.read<DiaryCubit>().state);
|
final selected =
|
||||||
if (widget.date != null) {
|
widget.date ?? _dayFromState(context.read<DiaryCubit>().state);
|
||||||
_selectedDay = widget.date!;
|
if (selected != null) {
|
||||||
_focusedDay = widget.date!;
|
|
||||||
} else if (selected != null) {
|
|
||||||
_selectedDay = selected;
|
_selectedDay = selected;
|
||||||
_focusedDay = selected;
|
_focusedDay = selected;
|
||||||
}
|
}
|
||||||
@@ -54,13 +62,30 @@ class _CalendarWidgetState extends State<CalendarWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_expansion.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final s = S.of(context);
|
final rowHeight = MediaQuery.textScalerOf(context).scale(_kRowHeight);
|
||||||
final textScaler = MediaQuery.textScalerOf(context);
|
final firstOfMonth = DateTime.utc(_focusedDay.year, _focusedDay.month);
|
||||||
final daysOfWeekHeight = _scaledDaysOfWeekHeight(context);
|
final daysInMonth = DateTime.utc(
|
||||||
return BlocConsumer<DiaryCubit, DiaryState>(
|
_focusedDay.year,
|
||||||
listener: (BuildContext context, DiaryState state) {
|
_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<DiaryCubit, DiaryState>(
|
||||||
|
listener: (context, state) {
|
||||||
final selected = _dayFromState(state);
|
final selected = _dayFromState(state);
|
||||||
if (selected != null) {
|
if (selected != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -69,80 +94,167 @@ class _CalendarWidgetState extends State<CalendarWidget> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
builder: (BuildContext context, DiaryState state) {
|
child: Padding(
|
||||||
return Column(
|
padding: const EdgeInsets.only(top: 4),
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: AnimatedBuilder(
|
||||||
children: [
|
animation: _expansion,
|
||||||
Padding(
|
child: _buildWeekdays(context),
|
||||||
padding: const EdgeInsets.only(top: 16),
|
builder: (context, weekdays) {
|
||||||
child: TableCalendar(
|
return Column(
|
||||||
focusedDay: _focusedDay,
|
mainAxisSize: MainAxisSize.min,
|
||||||
firstDay: DateTime.utc(2020, 10, 16),
|
children: [
|
||||||
lastDay: DateTime.utc(2030, 3, 14),
|
_buildHeader(context),
|
||||||
locale: 'ru_RU',
|
weekdays!,
|
||||||
startingDayOfWeek: StartingDayOfWeek.monday,
|
ClipRect(
|
||||||
calendarFormat: _calendarFormat,
|
child: SizedBox(
|
||||||
daysOfWeekHeight: daysOfWeekHeight,
|
height: rowHeight + extraHeight * _expansion.value,
|
||||||
rowHeight: textScaler.scale(_kRowHeight),
|
child: OverflowBox(
|
||||||
headerStyle: const HeaderStyle(titleCentered: true, formatButtonVisible: false, leftChevronVisible: false, rightChevronVisible: false),
|
// При раскрытии показываем строки вокруг открытой недели.
|
||||||
onDaySelected: (selectedDay, focusedDay) async {
|
alignment: Alignment(
|
||||||
if (!isSameDay(_selectedDay, selectedDay)) {
|
0,
|
||||||
final previousSelectedDay = _selectedDay;
|
2 * focusedWeek / (weekCount - 1) - 1,
|
||||||
final previousFocusedDay = _selectedDay;
|
),
|
||||||
setState(() {
|
minHeight: 0,
|
||||||
_selectedDay = selectedDay;
|
maxHeight: double.infinity,
|
||||||
_focusedDay = focusedDay;
|
child: _expansion.value == 0 ? week : month,
|
||||||
});
|
),
|
||||||
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;
|
|
||||||
_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,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
_buildDragHandle(extraHeight),
|
||||||
),
|
],
|
||||||
_arrowDown(),
|
);
|
||||||
],
|
},
|
||||||
);
|
),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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<void> _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<DiaryCubit>();
|
||||||
|
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) {
|
double _scaledDaysOfWeekHeight(BuildContext context) {
|
||||||
final painter = TextPainter(
|
final painter = TextPainter(
|
||||||
text: TextSpan(text: 'Щy', style: DefaultTextStyle.of(context).style),
|
text: TextSpan(text: 'Щy', style: DefaultTextStyle.of(context).style),
|
||||||
@@ -155,26 +267,44 @@ class _CalendarWidgetState extends State<CalendarWidget> {
|
|||||||
return height.clamp(_kDaysOfWeekHeight, double.infinity);
|
return height.clamp(_kDaysOfWeekHeight, double.infinity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _nextCalendarFormat() {
|
Widget _buildDragHandle(double extraHeight) {
|
||||||
setState(() {
|
|
||||||
_calendarFormat = CalendarFormat.values[(_calendarFormat.index - 1) % CalendarFormat.values.length];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
GestureDetector _arrowDown() {
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
behavior: HitTestBehavior.translucent,
|
behavior: HitTestBehavior.opaque,
|
||||||
onVerticalDragStart: (_) {
|
dragStartBehavior: DragStartBehavior.down,
|
||||||
_nextCalendarFormat();
|
onVerticalDragStart: (_) => _expansion.stop(),
|
||||||
|
onVerticalDragUpdate: (details) {
|
||||||
|
_expansion.value = (_expansion.value + details.delta.dy / extraHeight)
|
||||||
|
.clamp(0.0, 1.0);
|
||||||
},
|
},
|
||||||
onTap: () {
|
onVerticalDragEnd: (details) =>
|
||||||
_nextCalendarFormat();
|
_settleExpansion(details.velocity.pixelsPerSecond.dy),
|
||||||
},
|
onVerticalDragCancel: _settleExpansion,
|
||||||
child: Container(
|
child: SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
padding: const EdgeInsets.only(top: 8, bottom: 16),
|
child: Padding(
|
||||||
child: Icon(_calendarFormat == CalendarFormat.month ? Icons.keyboard_arrow_up_rounded : Icons.keyboard_arrow_down_rounded, color: Colors.grey.shade600),
|
// Отступ ячеек уже добавляет место над полоской.
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import 'package:share_plus/share_plus.dart';
|
|||||||
class PlanWidget extends StatefulWidget {
|
class PlanWidget extends StatefulWidget {
|
||||||
final PlanModel plan;
|
final PlanModel plan;
|
||||||
final int index;
|
final int index;
|
||||||
|
final bool showPriceOnCover;
|
||||||
final Future<void> Function(String slug)? onLikeTap;
|
final Future<void> Function(String slug)? onLikeTap;
|
||||||
final Future<void> Function(String slug, bool isFavorite)? onToggleFavorite;
|
final Future<void> Function(String slug, bool isFavorite)? onToggleFavorite;
|
||||||
final VoidCallback? onPlanChanged;
|
final VoidCallback? onPlanChanged;
|
||||||
@@ -30,6 +31,7 @@ class PlanWidget extends StatefulWidget {
|
|||||||
super.key,
|
super.key,
|
||||||
required this.plan,
|
required this.plan,
|
||||||
required this.index,
|
required this.index,
|
||||||
|
this.showPriceOnCover = false,
|
||||||
this.onLikeTap,
|
this.onLikeTap,
|
||||||
this.onToggleFavorite,
|
this.onToggleFavorite,
|
||||||
this.onPlanChanged,
|
this.onPlanChanged,
|
||||||
@@ -45,6 +47,10 @@ class _PlanWidgetState extends State<PlanWidget> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final s = S.of(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(
|
return InkWell(
|
||||||
onTap: () => GoRouter.of(context).pushNamed(
|
onTap: () => GoRouter.of(context).pushNamed(
|
||||||
'aboutPlanScreen',
|
'aboutPlanScreen',
|
||||||
@@ -119,14 +125,40 @@ class _PlanWidgetState extends State<PlanWidget> {
|
|||||||
),
|
),
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 16,
|
bottom: 16,
|
||||||
child: SizedBox(
|
left: 0,
|
||||||
width: MediaQuery.sizeOf(context).width,
|
right: 0,
|
||||||
child: InfoRow(
|
child: Column(
|
||||||
plan: widget.plan,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
itemsBackgroundColor: appTheme.whiteA700,
|
children: [
|
||||||
disableDescriptionOfTypes: true,
|
if (widget.showPriceOnCover)
|
||||||
type: ProductType.plan,
|
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<PlanWidget> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const Spacer(),
|
if (!widget.showPriceOnCover) ...[
|
||||||
Text(
|
const Spacer(),
|
||||||
'${widget.plan.packetsCount == 1 ? widget.plan.packet1Options?.price : '${s.from} ${widget.plan.minPriceOfOptions.toStringAsFixed(0)}'}₽',
|
Text(
|
||||||
style: TextStyles.headingXLSemibold.copyWith(
|
price,
|
||||||
color: appTheme.greenA700,
|
style: TextStyles.headingXLSemibold.copyWith(
|
||||||
|
color: appTheme.greenA700,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(width: 16),
|
||||||
const SizedBox(width: 16),
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
title: Padding(
|
title: Padding(
|
||||||
|
|||||||
@@ -39,12 +39,14 @@ class InsightsCard extends StatelessWidget {
|
|||||||
this.kbjuEnabled = InsightsFeatureFlags.kbjuEnabled,
|
this.kbjuEnabled = InsightsFeatureFlags.kbjuEnabled,
|
||||||
this.refreshToken = 0,
|
this.refreshToken = 0,
|
||||||
this.initialIntraDate,
|
this.initialIntraDate,
|
||||||
|
this.showShadow = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String? slug;
|
final String? slug;
|
||||||
final bool canAdd;
|
final bool canAdd;
|
||||||
final InsightsRepository? repository;
|
final InsightsRepository? repository;
|
||||||
final bool kbjuEnabled;
|
final bool kbjuEnabled;
|
||||||
|
final bool showShadow;
|
||||||
|
|
||||||
/// При смене значения блок перезапрашивает данные (например, после правок
|
/// При смене значения блок перезапрашивает данные (например, после правок
|
||||||
/// в дневнике), сохраняя вкладку, период и выбранный день.
|
/// в дневнике), сохраняя вкладку, период и выбранный день.
|
||||||
@@ -68,6 +70,7 @@ class InsightsCard extends StatelessWidget {
|
|||||||
child: _InsightsView(
|
child: _InsightsView(
|
||||||
refreshToken: refreshToken,
|
refreshToken: refreshToken,
|
||||||
initialIntraDate: initialIntraDate,
|
initialIntraDate: initialIntraDate,
|
||||||
|
showShadow: showShadow,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -78,10 +81,12 @@ class _InsightsView extends StatefulWidget {
|
|||||||
const _InsightsView({
|
const _InsightsView({
|
||||||
required this.refreshToken,
|
required this.refreshToken,
|
||||||
required this.initialIntraDate,
|
required this.initialIntraDate,
|
||||||
|
required this.showShadow,
|
||||||
});
|
});
|
||||||
|
|
||||||
final int refreshToken;
|
final int refreshToken;
|
||||||
final String? initialIntraDate;
|
final String? initialIntraDate;
|
||||||
|
final bool showShadow;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_InsightsView> createState() => _InsightsViewState();
|
State<_InsightsView> createState() => _InsightsViewState();
|
||||||
@@ -112,9 +117,13 @@ class _InsightsViewState extends State<_InsightsView> {
|
|||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return switch (state) {
|
return switch (state) {
|
||||||
InsightsStateLoaded() => _CardShell(
|
InsightsStateLoaded() => _CardShell(
|
||||||
|
showShadow: widget.showShadow,
|
||||||
child: _LoadedContent(state: state),
|
child: _LoadedContent(state: state),
|
||||||
),
|
),
|
||||||
InsightsStateError() => const _CardShell(child: _ErrorContent()),
|
InsightsStateError() => _CardShell(
|
||||||
|
showShadow: widget.showShadow,
|
||||||
|
child: const _ErrorContent(),
|
||||||
|
),
|
||||||
_ => const SizedBox.shrink(),
|
_ => const SizedBox.shrink(),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -123,9 +132,10 @@ class _InsightsViewState extends State<_InsightsView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _CardShell extends StatelessWidget {
|
class _CardShell extends StatelessWidget {
|
||||||
const _CardShell({required this.child});
|
const _CardShell({required this.child, required this.showShadow});
|
||||||
|
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
final bool showShadow;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -135,12 +145,13 @@ class _CardShell extends StatelessWidget {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
boxShadow: const [
|
boxShadow: [
|
||||||
BoxShadow(
|
if (showShadow)
|
||||||
color: InsightsColors.cardShadow,
|
const BoxShadow(
|
||||||
blurRadius: 4,
|
color: InsightsColors.cardShadow,
|
||||||
offset: Offset(0, 2),
|
blurRadius: 4,
|
||||||
),
|
offset: Offset(0, 2),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: child,
|
child: child,
|
||||||
|
|||||||
@@ -494,6 +494,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
return PlanWidget(
|
return PlanWidget(
|
||||||
plan: state.plansList[index],
|
plan: state.plansList[index],
|
||||||
index: index,
|
index: index,
|
||||||
|
showPriceOnCover: true,
|
||||||
onLikeTap: (slug) => plansCubit.likePlan(slug),
|
onLikeTap: (slug) => plansCubit.likePlan(slug),
|
||||||
onToggleFavorite: (slug, isFavorite) => isFavorite
|
onToggleFavorite: (slug, isFavorite) => isFavorite
|
||||||
? plansCubit.removePlanFromFavorite(slug)
|
? plansCubit.removePlanFromFavorite(slug)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import 'package:flutter/rendering.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:intl/date_symbol_data_local.dart';
|
import 'package:intl/date_symbol_data_local.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
import 'package:table_calendar/table_calendar.dart';
|
import 'package:table_calendar/table_calendar.dart';
|
||||||
|
|
||||||
class FakeDiaryCubit extends Cubit<DiaryState> implements DiaryCubit {
|
class FakeDiaryCubit extends Cubit<DiaryState> implements DiaryCubit {
|
||||||
@@ -28,15 +29,20 @@ void main() {
|
|||||||
theme: ThemeHelper().themeData(),
|
theme: ThemeHelper().themeData(),
|
||||||
builder: (context, appChild) {
|
builder: (context, appChild) {
|
||||||
return MediaQuery(
|
return MediaQuery(
|
||||||
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(textScale)),
|
data: MediaQuery.of(
|
||||||
|
context,
|
||||||
|
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||||
child: appChild!,
|
child: appChild!,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
localizationsDelegates: const [S.delegate, ...GlobalMaterialLocalizations.delegates],
|
localizationsDelegates: const [
|
||||||
|
S.delegate,
|
||||||
|
...GlobalMaterialLocalizations.delegates,
|
||||||
|
],
|
||||||
supportedLocales: const [Locale('ru')],
|
supportedLocales: const [Locale('ru')],
|
||||||
home: BlocProvider<DiaryCubit>.value(
|
home: BlocProvider<DiaryCubit>.value(
|
||||||
value: cubit,
|
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 {
|
testWidgets('scales weekday row when system font is large', (tester) async {
|
||||||
const textScale = 2.0;
|
const textScale = 2.0;
|
||||||
final cubit = FakeDiaryCubit(const DiaryState.loading());
|
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();
|
await tester.pump();
|
||||||
|
|
||||||
final calendar = tester.widget<TableCalendar<dynamic>>(find.byType(TableCalendar<dynamic>));
|
final calendar = tester.widget<TableCalendar<dynamic>>(
|
||||||
expect(calendar.daysOfWeekHeight, greaterThan(16 * textScale * 0.9));
|
find.byType(TableCalendar<dynamic>),
|
||||||
|
);
|
||||||
expect(calendar.rowHeight, 52 * textScale);
|
expect(calendar.rowHeight, 52 * textScale);
|
||||||
|
|
||||||
expect(find.text('пн'), findsWidgets);
|
expect(find.text('пн'), findsWidgets);
|
||||||
final weekday = tester.renderObject<RenderParagraph>(find.text('пн').first);
|
final weekday = tester.renderObject<RenderParagraph>(
|
||||||
expect(weekday.size.height, lessThanOrEqualTo(calendar.daysOfWeekHeight + 0.5));
|
find.text('пн').first,
|
||||||
|
);
|
||||||
|
expect(weekday.size.height, greaterThan(16 * textScale * 0.9));
|
||||||
|
expect(
|
||||||
|
tester.getBottomLeft(find.text('пн')).dy,
|
||||||
|
lessThanOrEqualTo(
|
||||||
|
tester.getTopLeft(find.byType(TableCalendar<dynamic>)).dy,
|
||||||
|
),
|
||||||
|
);
|
||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
|
|
||||||
await cubit.close();
|
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<dynamic>);
|
||||||
|
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));
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user