From 3d3be843731caea0a68460757660e4f287ec5107 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Mon, 25 Dec 2023 18:02:29 +0300 Subject: [PATCH] Added logic for Height and Weight --- .../height_screen/bloc/height_bloc.dart | 2 + .../height_screen/height_screen.dart | 38 +++++++++++-------- .../height_screen/models/height_model.dart | 9 ++++- .../weight_screen/bloc/weight_bloc.dart | 2 + .../weight_screen/models/weight_model.dart | 9 ++++- .../weight_screen/weight_screen.dart | 34 ++++++++++++----- 6 files changed, 64 insertions(+), 30 deletions(-) diff --git a/lib/presentation/height_screen/bloc/height_bloc.dart b/lib/presentation/height_screen/bloc/height_bloc.dart index 481fd778..629778fe 100644 --- a/lib/presentation/height_screen/bloc/height_bloc.dart +++ b/lib/presentation/height_screen/bloc/height_bloc.dart @@ -26,6 +26,8 @@ class HeightBloc extends Bloc { Emitter emit, ) { emit(state.copyWith(selectedDropDownValue: event.value)); + state.heightModelObj?.userRegistrationSheet.height = + int.tryParse(event.value.title)!; } List fillDropdownItemList() { diff --git a/lib/presentation/height_screen/height_screen.dart b/lib/presentation/height_screen/height_screen.dart index 3acd45a2..e258e465 100644 --- a/lib/presentation/height_screen/height_screen.dart +++ b/lib/presentation/height_screen/height_screen.dart @@ -13,10 +13,12 @@ class HeightScreen extends StatefulWidget { const HeightScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { + final sheet = + ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => - HeightBloc(HeightState(heightModelObj: HeightModel())) - ..add(HeightInitialEvent()), + create: (context) => HeightBloc(HeightState( + heightModelObj: HeightModel(userRegistrationSheet: sheet))) + ..add(HeightInitialEvent()), child: HeightScreen()); } @@ -84,12 +86,23 @@ class _HeightScreenState extends State { ]) ]), Spacer(), - NextStepButton( - text: "continue".tr.toUpperCase(), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: () { - navigateToAllergies(context); - }), + BlocBuilder( + builder: (context, state) { + return NextStepButton( + text: "continue".tr.toUpperCase(), + margin: EdgeInsets.only( + left: 16.h, right: 16.h, bottom: 50.v), + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + onPressed: () { + UserRegistrationSheet sheet = + state.heightModelObj!.userRegistrationSheet; + Navigator.pushNamed( + context, + AppRoutes.heightScreen, + arguments: sheet, + ); + }); + }), SizedBox(height: 17.v), ])))); } @@ -112,11 +125,4 @@ class _HeightScreenState extends State { onTapArrowLeft(BuildContext context) { NavigatorService.goBack(); } - - /// Navigates to the allergiesScreen when the action is triggered. - navigateToAllergies(BuildContext context) { - NavigatorService.pushNamed( - AppRoutes.allergiesScreen, - ); - } } diff --git a/lib/presentation/height_screen/models/height_model.dart b/lib/presentation/height_screen/models/height_model.dart index e2f18217..b108d7d9 100644 --- a/lib/presentation/height_screen/models/height_model.dart +++ b/lib/presentation/height_screen/models/height_model.dart @@ -2,20 +2,25 @@ import 'package:equatable/equatable.dart'; import 'package:eatvio_app/data/models/selectionPopupModel/selection_popup_model.dart'; +import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart'; /// This class defines the variables used in the [height_screen], /// and is typically used to hold data that is passed between different parts of the application. class HeightModel extends Equatable { - HeightModel({this.dropdownItemList = const []}); + UserRegistrationSheet userRegistrationSheet; + HeightModel( + {this.dropdownItemList = const [], required this.userRegistrationSheet}); List dropdownItemList; HeightModel copyWith({List? dropdownItemList}) { return HeightModel( + userRegistrationSheet: + userRegistrationSheet ?? this.userRegistrationSheet, dropdownItemList: dropdownItemList ?? this.dropdownItemList, ); } @override - List get props => [dropdownItemList]; + List get props => [dropdownItemList, userRegistrationSheet]; } diff --git a/lib/presentation/weight_screen/bloc/weight_bloc.dart b/lib/presentation/weight_screen/bloc/weight_bloc.dart index 37ce0901..94091376 100644 --- a/lib/presentation/weight_screen/bloc/weight_bloc.dart +++ b/lib/presentation/weight_screen/bloc/weight_bloc.dart @@ -26,6 +26,8 @@ class WeightBloc extends Bloc { Emitter emit, ) { emit(state.copyWith(selectedDropDownValue: event.value)); + state.weightModelObj?.userRegistrationSheet.weight = + int.tryParse(event.value.title)!; } List fillDropdownItemList() { diff --git a/lib/presentation/weight_screen/models/weight_model.dart b/lib/presentation/weight_screen/models/weight_model.dart index b4957007..e91ceb10 100644 --- a/lib/presentation/weight_screen/models/weight_model.dart +++ b/lib/presentation/weight_screen/models/weight_model.dart @@ -2,20 +2,25 @@ import 'package:equatable/equatable.dart'; import 'package:eatvio_app/data/models/selectionPopupModel/selection_popup_model.dart'; +import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart'; /// This class defines the variables used in the [weight_screen], /// and is typically used to hold data that is passed between different parts of the application. class WeightModel extends Equatable { - WeightModel({this.dropdownItemList = const []}); + UserRegistrationSheet userRegistrationSheet; + WeightModel( + {this.dropdownItemList = const [], required this.userRegistrationSheet}); List dropdownItemList; WeightModel copyWith({List? dropdownItemList}) { return WeightModel( + userRegistrationSheet: + userRegistrationSheet ?? this.userRegistrationSheet, dropdownItemList: dropdownItemList ?? this.dropdownItemList, ); } @override - List get props => [dropdownItemList]; + List get props => [dropdownItemList, userRegistrationSheet]; } diff --git a/lib/presentation/weight_screen/weight_screen.dart b/lib/presentation/weight_screen/weight_screen.dart index aad4c57d..8e606e1c 100644 --- a/lib/presentation/weight_screen/weight_screen.dart +++ b/lib/presentation/weight_screen/weight_screen.dart @@ -6,16 +6,19 @@ import 'package:eatvio_app/widgets/app_bar/appbar_title_image.dart'; import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart'; import 'package:eatvio_app/widgets/custom_drop_down.dart'; import 'package:eatvio_app/widgets/next_step_button.dart'; +import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart'; import 'package:flutter/material.dart'; class WeightScreen extends StatefulWidget { const WeightScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { + final sheet = + ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => - WeightBloc(WeightState(weightModelObj: WeightModel())) - ..add(WeightInitialEvent()), + create: (context) => WeightBloc(WeightState( + weightModelObj: WeightModel(userRegistrationSheet: sheet))) + ..add(WeightInitialEvent()), child: WeightScreen()); } @@ -72,7 +75,7 @@ class _WeightScreenState extends State { imagePath: ImageConstant.imgFavorite, height: 12.adaptSize, width: 12.adaptSize)), - hintText: "70", + hintText: "Не выбрано", items: weightModelObj?.dropdownItemList ?? [], onChanged: (value) { context @@ -83,12 +86,23 @@ class _WeightScreenState extends State { ]) ]), Spacer(), - NextStepButton( - text: "continue".tr.toUpperCase(), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: () { - navigateToHeight(context); - }), + BlocBuilder( + builder: (context, state) { + return NextStepButton( + text: "continue".tr.toUpperCase(), + margin: EdgeInsets.only( + left: 16.h, right: 16.h, bottom: 50.v), + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + onPressed: () { + UserRegistrationSheet sheet = + state.weightModelObj!.userRegistrationSheet; + Navigator.pushNamed( + context, + AppRoutes.heightScreen, + arguments: sheet, + ); + }); + }), SizedBox(height: 17.v), ])))); }