From fda601106aca97841da8c639d9a33e0e8c60518f Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Wed, 28 Aug 2024 12:58:31 +0300 Subject: [PATCH] feat(menu): add menu screen, method for add weight --- lib/app_router.dart | 21 +- .../widgets/bottom_navigation_bar_widget.dart | 17 +- .../menu/presentation/pages/menu_screen.dart | 96 +++++++ .../pages/notifications_screen.dart | 14 + .../profile/models/profile_model.dart | 15 +- .../profile/models/profile_model.freezed.dart | 259 +++++++++++++++++- .../profile/models/profile_model.g.dart | 22 +- .../bloc/profile_cubit/profile_cubit.dart | 14 + .../presentation/pages/profile_screen.dart | 97 +------ .../widgets/circumference_chart_widget.dart | 107 ++++++++ .../repositories/profile_repository.dart | 14 + .../profile/services/profile_service.dart | 5 + .../profile/services/profile_service.g.dart | 38 +++ lib/widgets/custom_navigation_menu.dart | 77 ------ 14 files changed, 589 insertions(+), 207 deletions(-) create mode 100644 lib/features/menu/presentation/pages/menu_screen.dart create mode 100644 lib/features/notifications/presentation/pages/notifications_screen.dart create mode 100644 lib/features/profile/presentation/widgets/circumference_chart_widget.dart delete mode 100644 lib/widgets/custom_navigation_menu.dart diff --git a/lib/app_router.dart b/lib/app_router.dart index 3a662763..f872ddc9 100644 --- a/lib/app_router.dart +++ b/lib/app_router.dart @@ -13,6 +13,8 @@ import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart'; import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart'; import 'package:eatvio_app/features/feed/models/recipes_model.dart'; import 'package:eatvio_app/features/feed/presentation/pages/feed_screen.dart'; +import 'package:eatvio_app/features/menu/presentation/pages/menu_screen.dart'; +import 'package:eatvio_app/features/notifications/presentation/pages/notifications_screen.dart'; import 'package:eatvio_app/features/profile/presentation/pages/profile_screen.dart'; import 'package:eatvio_app/features/recipes/presentation/pages/about_recipes_screen.dart'; import 'package:eatvio_app/features/recipes/presentation/pages/recipe_create_screen.dart'; @@ -68,13 +70,11 @@ class AppRouter { await context.read().runInitialization(); return null; }, - // builder: (context, state) => MyProfileScreen(), ), GoRoute( pageBuilder: (context, state) => NoTransitionPage(child: FeedScreen()), path: '/feed-screen', name: 'feedScreen', - // builder: (context, state) => FeedScreen(), ), GoRoute( pageBuilder: (context, state) { @@ -85,18 +85,21 @@ class AppRouter { }, path: '/diary-screen', name: 'diaryScreen', - // builder: (context, state) { - // if (state.extra != null) - // return DiaryScreen(diaryID: state.extra as String); - // else - // return DiaryScreen(diaryID: '0'); - // }, ), GoRoute( pageBuilder: (context, state) => NoTransitionPage(child: ChatSelectScreen()), path: '/chat-select-screen', name: 'chatSelectScreen', - // builder: (context, state) => ChatSelectScreen(), + ), + GoRoute( + pageBuilder: (context, state) => NoTransitionPage(child: NotificationsScreen()), + path: '/notifications-screen', + name: 'notificationsScreen', + ), + GoRoute( + pageBuilder: (context, state) => NoTransitionPage(child: MenuScreen()), + path: '/menu-screen', + name: 'menuScreen', ), ], ), diff --git a/lib/features/bottom_navigation_bar/presentation/widgets/bottom_navigation_bar_widget.dart b/lib/features/bottom_navigation_bar/presentation/widgets/bottom_navigation_bar_widget.dart index a7e12393..356d3cc7 100644 --- a/lib/features/bottom_navigation_bar/presentation/widgets/bottom_navigation_bar_widget.dart +++ b/lib/features/bottom_navigation_bar/presentation/widgets/bottom_navigation_bar_widget.dart @@ -6,7 +6,6 @@ import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/noti import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/notifications_cubit/notifications_state.dart'; import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/profile_avatar_cubit/profile_avatar_cubit.dart'; import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/profile_avatar_cubit/profile_avatar_state.dart'; -import 'package:eatvio_app/widgets/custom_navigation_menu.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:go_router/go_router.dart'; @@ -46,22 +45,10 @@ class _BottomNavigationBarWidgetState extends State { GoRouter.of(context).replace('/chat-select-screen'); break; case 4: + GoRouter.of(context).replace('/notifications-screen'); break; case 5: - final RenderBox overlay = Overlay.of(context).context.findRenderObject() as RenderBox; - final size = overlay.size; - showMenu( - context: context, - color: Colors.white, - shadowColor: Colors.white, - surfaceTintColor: Colors.white, - items: [ - PopupMenuItem( - child: CustomNavigationMenu(), - ), - ], - position: RelativeRect.fromLTRB(size.width, size.height, 0, 0), - ); + GoRouter.of(context).replace('/menu-screen'); break; } } diff --git a/lib/features/menu/presentation/pages/menu_screen.dart b/lib/features/menu/presentation/pages/menu_screen.dart new file mode 100644 index 00000000..d7074834 --- /dev/null +++ b/lib/features/menu/presentation/pages/menu_screen.dart @@ -0,0 +1,96 @@ +import 'package:dio/dio.dart'; +import 'package:eatvio_app/core/constants/constants.dart'; +import 'package:eatvio_app/core/token_storage.dart'; +import 'package:eatvio_app/core/utils/image_constant.dart'; +import 'package:eatvio_app/locator_service.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_svg/flutter_svg.dart'; +import 'package:go_router/go_router.dart'; + +class MenuScreen extends StatelessWidget { + const MenuScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Меню'), + ), + body: SingleChildScrollView( + child: Column( + children: [ + _tile( + title: 'Настройки профиля', + leading: ImageConstant.icnProfileSettings, + onTap: () => GoRouter.of(context).push('/my-settings-screen'), + ), + _tile( + leading: ImageConstant.icnRecipes, + title: 'Мои рецепты', + onTap: () => GoRouter.of(context).push('/recipe-select-screen'), + ), + _tile( + leading: 'assets/icons/diets.svg', + title: 'Мои диеты', + onTap: () => GoRouter.of(context).push('/diet-select-screen'), + ), + _tile( + leading: ImageConstant.icnPlans, + title: 'Мои планы', + onTap: () => GoRouter.of(context).push('/plan-select-screen'), + ), + _tile( + leading: 'assets/icons/calendar.svg', + title: 'Календарь', + onTap: () => GoRouter.of(context).push('/calendar-screen'), + ), + _tile( + leading: ImageConstant.icnGlossary, + title: 'Глоссарий', + onTap: () => GoRouter.of(context).push('/glossary-screen'), + ), + _tile( + leading: ImageConstant.icnSupport, + title: 'Поддержка', + onTap: () {}, + ), + _tile( + leading: ImageConstant.icnExit, + title: 'Выход', + onTap: _onTapLogout(context), + ), + ], + ), + ), + ); + } + + _tile({ + required String title, + required String leading, + required Function() onTap, + }) { + return ListTile( + onTap: onTap, + leading: SvgPicture.asset( + leading, + height: 24, + width: 24, + ), + title: Text(title), + ); + } + + _onTapLogout(BuildContext context) { + return () async { + final response = await sl().post( + baseUrl + '/api/profile/logout', + ); + + if (response.statusCode == 204) { + await TokenStorage.removeTokenInStorage(); + GoRouter.of(context).go('/auth-screen'); + } + }; + } +} diff --git a/lib/features/notifications/presentation/pages/notifications_screen.dart b/lib/features/notifications/presentation/pages/notifications_screen.dart new file mode 100644 index 00000000..6d979118 --- /dev/null +++ b/lib/features/notifications/presentation/pages/notifications_screen.dart @@ -0,0 +1,14 @@ +import 'package:flutter/material.dart'; + +class NotificationsScreen extends StatelessWidget { + const NotificationsScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Уведомления'), + ), + ); + } +} diff --git a/lib/features/profile/models/profile_model.dart b/lib/features/profile/models/profile_model.dart index e7dd87f1..742c9c90 100644 --- a/lib/features/profile/models/profile_model.dart +++ b/lib/features/profile/models/profile_model.dart @@ -6,7 +6,7 @@ part 'profile_model.g.dart'; class ProfileModel with _$ProfileModel { const factory ProfileModel({ @JsonKey(name: "user") required User user, - @JsonKey(name: "chartPoints") required List chartPoints, + @JsonKey(name: "chartPoints") required List chartPoints, @JsonKey(name: "userDetails") required UserDetails userDetails, @JsonKey(name: "circumferences") required List circumferences, @JsonKey(name: "finishedPlans") required List finishedPlans, @@ -94,3 +94,16 @@ class UserDetails with _$UserDetails { factory UserDetails.fromJson(Map json) => _$UserDetailsFromJson(json); } + +@freezed +class ChartPoint with _$ChartPoint { + const factory ChartPoint({ + @JsonKey(name: "id") required int id, + @JsonKey(name: "user_id") required int userId, + @JsonKey(name: "weight") required int weight, + @JsonKey(name: "created_at") required DateTime createdAt, + @JsonKey(name: "updated_at") required DateTime updatedAt, + }) = _ChartPoint; + + factory ChartPoint.fromJson(Map json) => _$ChartPointFromJson(json); +} diff --git a/lib/features/profile/models/profile_model.freezed.dart b/lib/features/profile/models/profile_model.freezed.dart index 29d3b3c4..4fe3b775 100644 --- a/lib/features/profile/models/profile_model.freezed.dart +++ b/lib/features/profile/models/profile_model.freezed.dart @@ -23,7 +23,7 @@ mixin _$ProfileModel { @JsonKey(name: "user") User get user => throw _privateConstructorUsedError; @JsonKey(name: "chartPoints") - List get chartPoints => throw _privateConstructorUsedError; + List get chartPoints => throw _privateConstructorUsedError; @JsonKey(name: "userDetails") UserDetails get userDetails => throw _privateConstructorUsedError; @JsonKey(name: "circumferences") @@ -55,7 +55,7 @@ abstract class $ProfileModelCopyWith<$Res> { @useResult $Res call( {@JsonKey(name: "user") User user, - @JsonKey(name: "chartPoints") List chartPoints, + @JsonKey(name: "chartPoints") List chartPoints, @JsonKey(name: "userDetails") UserDetails userDetails, @JsonKey(name: "circumferences") List circumferences, @JsonKey(name: "finishedPlans") List finishedPlans, @@ -101,7 +101,7 @@ class _$ProfileModelCopyWithImpl<$Res, $Val extends ProfileModel> chartPoints: null == chartPoints ? _value.chartPoints : chartPoints // ignore: cast_nullable_to_non_nullable - as List, + as List, userDetails: null == userDetails ? _value.userDetails : userDetails // ignore: cast_nullable_to_non_nullable @@ -164,7 +164,7 @@ abstract class _$$ProfileModelImplCopyWith<$Res> @useResult $Res call( {@JsonKey(name: "user") User user, - @JsonKey(name: "chartPoints") List chartPoints, + @JsonKey(name: "chartPoints") List chartPoints, @JsonKey(name: "userDetails") UserDetails userDetails, @JsonKey(name: "circumferences") List circumferences, @JsonKey(name: "finishedPlans") List finishedPlans, @@ -210,7 +210,7 @@ class __$$ProfileModelImplCopyWithImpl<$Res> chartPoints: null == chartPoints ? _value._chartPoints : chartPoints // ignore: cast_nullable_to_non_nullable - as List, + as List, userDetails: null == userDetails ? _value.userDetails : userDetails // ignore: cast_nullable_to_non_nullable @@ -252,7 +252,7 @@ class __$$ProfileModelImplCopyWithImpl<$Res> class _$ProfileModelImpl implements _ProfileModel { const _$ProfileModelImpl( {@JsonKey(name: "user") required this.user, - @JsonKey(name: "chartPoints") required final List chartPoints, + @JsonKey(name: "chartPoints") required final List chartPoints, @JsonKey(name: "userDetails") required this.userDetails, @JsonKey(name: "circumferences") required final List circumferences, @@ -280,10 +280,10 @@ class _$ProfileModelImpl implements _ProfileModel { @override @JsonKey(name: "user") final User user; - final List _chartPoints; + final List _chartPoints; @override @JsonKey(name: "chartPoints") - List get chartPoints { + List get chartPoints { if (_chartPoints is EqualUnmodifiableListView) return _chartPoints; // ignore: implicit_dynamic_type return EqualUnmodifiableListView(_chartPoints); @@ -417,7 +417,7 @@ class _$ProfileModelImpl implements _ProfileModel { abstract class _ProfileModel implements ProfileModel { const factory _ProfileModel( {@JsonKey(name: "user") required final User user, - @JsonKey(name: "chartPoints") required final List chartPoints, + @JsonKey(name: "chartPoints") required final List chartPoints, @JsonKey(name: "userDetails") required final UserDetails userDetails, @JsonKey(name: "circumferences") required final List circumferences, @@ -440,7 +440,7 @@ abstract class _ProfileModel implements ProfileModel { User get user; @override @JsonKey(name: "chartPoints") - List get chartPoints; + List get chartPoints; @override @JsonKey(name: "userDetails") UserDetails get userDetails; @@ -2109,3 +2109,242 @@ abstract class _UserDetails implements UserDetails { _$$UserDetailsImplCopyWith<_$UserDetailsImpl> get copyWith => throw _privateConstructorUsedError; } + +ChartPoint _$ChartPointFromJson(Map json) { + return _ChartPoint.fromJson(json); +} + +/// @nodoc +mixin _$ChartPoint { + @JsonKey(name: "id") + int get id => throw _privateConstructorUsedError; + @JsonKey(name: "user_id") + int get userId => throw _privateConstructorUsedError; + @JsonKey(name: "weight") + int get weight => throw _privateConstructorUsedError; + @JsonKey(name: "created_at") + DateTime get createdAt => throw _privateConstructorUsedError; + @JsonKey(name: "updated_at") + DateTime get updatedAt => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $ChartPointCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ChartPointCopyWith<$Res> { + factory $ChartPointCopyWith( + ChartPoint value, $Res Function(ChartPoint) then) = + _$ChartPointCopyWithImpl<$Res, ChartPoint>; + @useResult + $Res call( + {@JsonKey(name: "id") int id, + @JsonKey(name: "user_id") int userId, + @JsonKey(name: "weight") int weight, + @JsonKey(name: "created_at") DateTime createdAt, + @JsonKey(name: "updated_at") DateTime updatedAt}); +} + +/// @nodoc +class _$ChartPointCopyWithImpl<$Res, $Val extends ChartPoint> + implements $ChartPointCopyWith<$Res> { + _$ChartPointCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? userId = null, + Object? weight = null, + Object? createdAt = null, + Object? updatedAt = null, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + userId: null == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int, + weight: null == weight + ? _value.weight + : weight // ignore: cast_nullable_to_non_nullable + as int, + createdAt: null == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as DateTime, + updatedAt: null == updatedAt + ? _value.updatedAt + : updatedAt // ignore: cast_nullable_to_non_nullable + as DateTime, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$ChartPointImplCopyWith<$Res> + implements $ChartPointCopyWith<$Res> { + factory _$$ChartPointImplCopyWith( + _$ChartPointImpl value, $Res Function(_$ChartPointImpl) then) = + __$$ChartPointImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: "id") int id, + @JsonKey(name: "user_id") int userId, + @JsonKey(name: "weight") int weight, + @JsonKey(name: "created_at") DateTime createdAt, + @JsonKey(name: "updated_at") DateTime updatedAt}); +} + +/// @nodoc +class __$$ChartPointImplCopyWithImpl<$Res> + extends _$ChartPointCopyWithImpl<$Res, _$ChartPointImpl> + implements _$$ChartPointImplCopyWith<$Res> { + __$$ChartPointImplCopyWithImpl( + _$ChartPointImpl _value, $Res Function(_$ChartPointImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? userId = null, + Object? weight = null, + Object? createdAt = null, + Object? updatedAt = null, + }) { + return _then(_$ChartPointImpl( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + userId: null == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int, + weight: null == weight + ? _value.weight + : weight // ignore: cast_nullable_to_non_nullable + as int, + createdAt: null == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as DateTime, + updatedAt: null == updatedAt + ? _value.updatedAt + : updatedAt // ignore: cast_nullable_to_non_nullable + as DateTime, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$ChartPointImpl implements _ChartPoint { + const _$ChartPointImpl( + {@JsonKey(name: "id") required this.id, + @JsonKey(name: "user_id") required this.userId, + @JsonKey(name: "weight") required this.weight, + @JsonKey(name: "created_at") required this.createdAt, + @JsonKey(name: "updated_at") required this.updatedAt}); + + factory _$ChartPointImpl.fromJson(Map json) => + _$$ChartPointImplFromJson(json); + + @override + @JsonKey(name: "id") + final int id; + @override + @JsonKey(name: "user_id") + final int userId; + @override + @JsonKey(name: "weight") + final int weight; + @override + @JsonKey(name: "created_at") + final DateTime createdAt; + @override + @JsonKey(name: "updated_at") + final DateTime updatedAt; + + @override + String toString() { + return 'ChartPoint(id: $id, userId: $userId, weight: $weight, createdAt: $createdAt, updatedAt: $updatedAt)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ChartPointImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.userId, userId) || other.userId == userId) && + (identical(other.weight, weight) || other.weight == weight) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.updatedAt, updatedAt) || + other.updatedAt == updatedAt)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => + Object.hash(runtimeType, id, userId, weight, createdAt, updatedAt); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$ChartPointImplCopyWith<_$ChartPointImpl> get copyWith => + __$$ChartPointImplCopyWithImpl<_$ChartPointImpl>(this, _$identity); + + @override + Map toJson() { + return _$$ChartPointImplToJson( + this, + ); + } +} + +abstract class _ChartPoint implements ChartPoint { + const factory _ChartPoint( + {@JsonKey(name: "id") required final int id, + @JsonKey(name: "user_id") required final int userId, + @JsonKey(name: "weight") required final int weight, + @JsonKey(name: "created_at") required final DateTime createdAt, + @JsonKey(name: "updated_at") required final DateTime updatedAt}) = + _$ChartPointImpl; + + factory _ChartPoint.fromJson(Map json) = + _$ChartPointImpl.fromJson; + + @override + @JsonKey(name: "id") + int get id; + @override + @JsonKey(name: "user_id") + int get userId; + @override + @JsonKey(name: "weight") + int get weight; + @override + @JsonKey(name: "created_at") + DateTime get createdAt; + @override + @JsonKey(name: "updated_at") + DateTime get updatedAt; + @override + @JsonKey(ignore: true) + _$$ChartPointImplCopyWith<_$ChartPointImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/features/profile/models/profile_model.g.dart b/lib/features/profile/models/profile_model.g.dart index 7197b817..5f3293aa 100644 --- a/lib/features/profile/models/profile_model.g.dart +++ b/lib/features/profile/models/profile_model.g.dart @@ -9,7 +9,9 @@ part of 'profile_model.dart'; _$ProfileModelImpl _$$ProfileModelImplFromJson(Map json) => _$ProfileModelImpl( user: User.fromJson(json['user'] as Map), - chartPoints: json['chartPoints'] as List, + chartPoints: (json['chartPoints'] as List) + .map((e) => ChartPoint.fromJson(e as Map)) + .toList(), userDetails: UserDetails.fromJson(json['userDetails'] as Map), circumferences: (json['circumferences'] as List) @@ -161,3 +163,21 @@ Map _$$UserDetailsImplToJson(_$UserDetailsImpl instance) => 'is_bedtime_fillable': instance.isBedtimeFillable, 'activity_coefficient': instance.activityCoefficient, }; + +_$ChartPointImpl _$$ChartPointImplFromJson(Map json) => + _$ChartPointImpl( + id: (json['id'] as num).toInt(), + userId: (json['user_id'] as num).toInt(), + weight: (json['weight'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + ); + +Map _$$ChartPointImplToJson(_$ChartPointImpl instance) => + { + 'id': instance.id, + 'user_id': instance.userId, + 'weight': instance.weight, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + }; diff --git a/lib/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart b/lib/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart index 34f6385e..0a08e8de 100644 --- a/lib/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart +++ b/lib/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart @@ -44,6 +44,20 @@ class ProfileCubit extends Cubit { ); } catch (e) { emit(ProfileState.error(errorMessage: e.toString())); + print(e); + } + } + + addWeight({ + required int weight, + }) async { + try { + await profileRepository.addWeight( + weight: weight, + ); + } catch (e) { + emit(ProfileState.error(errorMessage: e.toString())); + print(e); } } } diff --git a/lib/features/profile/presentation/pages/profile_screen.dart b/lib/features/profile/presentation/pages/profile_screen.dart index 5bd5154a..a6a78342 100644 --- a/lib/features/profile/presentation/pages/profile_screen.dart +++ b/lib/features/profile/presentation/pages/profile_screen.dart @@ -3,10 +3,9 @@ import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart'; import 'package:eatvio_app/features/profile/models/profile_model.dart'; import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart'; import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_state.dart'; +import 'package:eatvio_app/features/profile/presentation/widgets/circumference_chart_widget.dart'; import 'package:eatvio_app/locator_service.dart'; import 'package:flutter/material.dart'; -import 'package:intl/intl.dart'; -import 'package:syncfusion_flutter_charts/charts.dart'; class ProfileScreen extends StatefulWidget { final Author? author; @@ -35,8 +34,7 @@ class _ProfileScreenState extends State { chartData = state.profile.circumferences; return Scaffold( appBar: AppBar( - centerTitle: false, - title: Text(state.profile.user.name), + toolbarHeight: 0, ), body: SingleChildScrollView( child: Column( @@ -49,36 +47,7 @@ class _ProfileScreenState extends State { backgroundImage: NetworkImage(state.profile.user.profilePhotoUrl), ), ), - SfCartesianChart( - margin: EdgeInsets.zero, - enableAxisAnimation: true, - enableSideBySideSeriesPlacement: true, - legend: const Legend( - isVisible: true, - opacity: 0.7, - position: LegendPosition.bottom, - ), - plotAreaBorderWidth: 0, - trackballBehavior: TrackballBehavior( - enable: true, - activationMode: ActivationMode.singleTap, - ), - primaryXAxis: DateTimeAxis( - dateFormat: DateFormat.MMMd('ru'), - axisLine: AxisLine( - width: 1, - ), - ), - primaryYAxis: NumericAxis( - labelFormat: '{value} см', - axisLine: AxisLine( - width: 1, - ), - majorTickLines: MajorTickLines(size: 0), - ), - series: _getSplineAreaSeries(), - tooltipBehavior: TooltipBehavior(enable: true), - ), + CircumferenceChartWidget(chartData: chartData), ], ), ), @@ -105,64 +74,4 @@ class _ProfileScreenState extends State { ), ); } - - List> _getSplineAreaSeries() { - final Color seriesColor1 = Colors.red; - final Color seriesColor2 = Colors.blue; - final Color seriesColor3 = Colors.green; - - return >[ - SplineSeries( - markerSettings: MarkerSettings( - isVisible: true, - color: seriesColor1, - height: 12, - width: 12, - ), - dataLabelSettings: DataLabelSettings( - labelAlignment: ChartDataLabelAlignment.top, - isVisible: true, - ), - dataSource: chartData, - color: seriesColor1, - name: 'Грудь', - xValueMapper: (Circumference value, int index) => value.createdAt, - yValueMapper: (Circumference value, int index) => value.chestCircumference, - ), - SplineSeries( - markerSettings: MarkerSettings( - isVisible: true, - color: seriesColor2, - height: 12, - width: 12, - ), - dataLabelSettings: DataLabelSettings( - labelAlignment: ChartDataLabelAlignment.top, - isVisible: true, - ), - dataSource: chartData, - color: seriesColor2, - name: 'Талия', - xValueMapper: (Circumference value, int index) => value.createdAt, - yValueMapper: (Circumference value, int index) => value.waistCircumference, - ), - SplineSeries( - markerSettings: MarkerSettings( - isVisible: true, - color: seriesColor3, - height: 12, - width: 12, - ), - dataLabelSettings: DataLabelSettings( - labelAlignment: ChartDataLabelAlignment.top, - isVisible: true, - ), - dataSource: chartData, - color: seriesColor3, - name: 'Бёдра', - xValueMapper: (Circumference value, int index) => value.createdAt, - yValueMapper: (Circumference value, int index) => value.hipCircumference, - ), - ]; - } } diff --git a/lib/features/profile/presentation/widgets/circumference_chart_widget.dart b/lib/features/profile/presentation/widgets/circumference_chart_widget.dart new file mode 100644 index 00000000..a4a6af7a --- /dev/null +++ b/lib/features/profile/presentation/widgets/circumference_chart_widget.dart @@ -0,0 +1,107 @@ +import 'package:eatvio_app/features/profile/models/profile_model.dart'; +import 'package:flutter/material.dart'; +import 'package:syncfusion_flutter_charts/charts.dart'; +import 'package:intl/intl.dart'; + +class CircumferenceChartWidget extends StatelessWidget { + final List chartData; + + const CircumferenceChartWidget({ + super.key, + required this.chartData, + }); + + @override + Widget build(BuildContext context) { + return SfCartesianChart( + margin: EdgeInsets.zero, + enableAxisAnimation: true, + enableSideBySideSeriesPlacement: true, + legend: const Legend( + isVisible: true, + opacity: 0.7, + position: LegendPosition.bottom, + ), + plotAreaBorderWidth: 0, + trackballBehavior: TrackballBehavior( + enable: true, + activationMode: ActivationMode.singleTap, + ), + primaryXAxis: DateTimeAxis( + dateFormat: DateFormat.MMMd('ru'), + axisLine: AxisLine( + width: 1, + ), + ), + primaryYAxis: NumericAxis( + labelFormat: '{value} см', + axisLine: AxisLine( + width: 1, + ), + majorTickLines: MajorTickLines(size: 0), + ), + series: _getSplineSeries(), + tooltipBehavior: TooltipBehavior(enable: true), + ); + } + + List> _getSplineSeries() { + final Color seriesColor1 = Colors.red; + final Color seriesColor2 = Colors.blue; + final Color seriesColor3 = Colors.green; + + return >[ + SplineSeries( + markerSettings: MarkerSettings( + isVisible: true, + color: seriesColor1, + height: 12, + width: 12, + ), + dataLabelSettings: DataLabelSettings( + labelAlignment: ChartDataLabelAlignment.top, + isVisible: true, + ), + dataSource: chartData, + color: seriesColor1, + name: 'Грудь', + xValueMapper: (Circumference value, int index) => value.createdAt, + yValueMapper: (Circumference value, int index) => value.chestCircumference, + ), + SplineSeries( + markerSettings: MarkerSettings( + isVisible: true, + color: seriesColor2, + height: 12, + width: 12, + ), + dataLabelSettings: DataLabelSettings( + labelAlignment: ChartDataLabelAlignment.top, + isVisible: true, + ), + dataSource: chartData, + color: seriesColor2, + name: 'Талия', + xValueMapper: (Circumference value, int index) => value.createdAt, + yValueMapper: (Circumference value, int index) => value.waistCircumference, + ), + SplineSeries( + markerSettings: MarkerSettings( + isVisible: true, + color: seriesColor3, + height: 12, + width: 12, + ), + dataLabelSettings: DataLabelSettings( + labelAlignment: ChartDataLabelAlignment.top, + isVisible: true, + ), + dataSource: chartData, + color: seriesColor3, + name: 'Бёдра', + xValueMapper: (Circumference value, int index) => value.createdAt, + yValueMapper: (Circumference value, int index) => value.hipCircumference, + ), + ]; + } +} diff --git a/lib/features/profile/repositories/profile_repository.dart b/lib/features/profile/repositories/profile_repository.dart index a57be856..e859c8d6 100644 --- a/lib/features/profile/repositories/profile_repository.dart +++ b/lib/features/profile/repositories/profile_repository.dart @@ -39,4 +39,18 @@ class ProfileRepository { rethrow; } } + + Future addWeight({ + required int weight, + }) async { + try { + return (await profileService.addWeight( + weight: weight, + )) + .values + .first; + } catch (e) { + rethrow; + } + } } diff --git a/lib/features/profile/services/profile_service.dart b/lib/features/profile/services/profile_service.dart index dc9f2864..9966a82d 100644 --- a/lib/features/profile/services/profile_service.dart +++ b/lib/features/profile/services/profile_service.dart @@ -22,4 +22,9 @@ abstract class ProfileService { @Part(name: 'waist_circumference') required int waistCircumference, @Part(name: 'hip_circumference') required int hipCircumference, }); + + @POST('/api/profile/addWeight') + Future> addWeight({ + @Part() required int weight, + }); } diff --git a/lib/features/profile/services/profile_service.g.dart b/lib/features/profile/services/profile_service.g.dart index 7b2969ad..96b65b4d 100644 --- a/lib/features/profile/services/profile_service.g.dart +++ b/lib/features/profile/services/profile_service.g.dart @@ -137,6 +137,44 @@ class _ProfileService implements ProfileService { return _value; } + @override + Future> addWeight({required int weight}) async { + final _extra = {}; + final queryParameters = {}; + final _headers = {}; + final _data = FormData(); + _data.fields.add(MapEntry( + 'weight', + weight.toString(), + )); + final _options = _setStreamType>(Options( + method: 'POST', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/api/profile/addWeight', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + ))); + final _result = await _dio.fetch>(_options); + late Map _value; + try { + _value = _result.data!.map((k, dynamic v) => + MapEntry(k, ChartPoint.fromJson(v as Map))); + } on Object catch (e, s) { + errorLogger?.logError(e, s, _options); + rethrow; + } + return _value; + } + RequestOptions _setStreamType(RequestOptions requestOptions) { if (T != dynamic && !(requestOptions.responseType == ResponseType.bytes || diff --git a/lib/widgets/custom_navigation_menu.dart b/lib/widgets/custom_navigation_menu.dart deleted file mode 100644 index c3222e62..00000000 --- a/lib/widgets/custom_navigation_menu.dart +++ /dev/null @@ -1,77 +0,0 @@ -import 'package:eatvio_app/core/app_export.dart'; -import 'package:eatvio_app/core/token_storage.dart'; -import 'package:eatvio_app/widgets/custom_navigation_menu_item.dart'; -import 'package:flutter/material.dart'; -import 'package:go_router/go_router.dart'; -import 'package:http/http.dart' as http; - -class CustomNavigationMenu extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Container( - color: Colors.white, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - MenuItem( - icon: ImageConstant.icnProfileSettings, - text: 'Настройки профиля', - onTap: () => GoRouter.of(context).push('/my-settings-screen'), - ), - MenuItem( - icon: ImageConstant.icnRecipes, - text: 'Мои рецепты', - onTap: () => GoRouter.of(context).push('/recipe-select-screen'), - ), - MenuItem( - icon: 'assets/icons/diets.svg', - text: 'Мои диеты', - onTap: () => GoRouter.of(context).push('/diet-select-screen'), - ), - MenuItem( - icon: ImageConstant.icnPlans, - text: 'Мои планы', - onTap: () => GoRouter.of(context).push('/plan-select-screen'), - ), - MenuItem( - icon: 'assets/icons/calendar.svg', - text: 'Календарь', - onTap: () => GoRouter.of(context).push('/calendar-screen'), - ), - MenuItem( - icon: ImageConstant.icnGlossary, - text: 'Глоссарий', - onTap: () => GoRouter.of(context).push('/glossary-screen'), - ), - MenuItem( - icon: ImageConstant.icnSupport, - text: 'Поддержка', - onTap: () {}, - ), - MenuItem( - icon: ImageConstant.icnExit, - text: 'Выход', - onTap: _onTapLogout(context), - ), - ], - ), - ); - } -} - -_onTapLogout(BuildContext context) { - return () async { - final token = await TokenStorage.getTokenFromStorage(); - final response = await http.post( - Uri.parse(baseUrl + '/api/profile/logout'), - headers: { - 'Authorization': 'Bearer $token', - }, - ); - - if (response.statusCode == 204) { - await TokenStorage.removeTokenInStorage(); - GoRouter.of(context).go('/auth-screen'); - } - }; -}