From aa1ab31a9195e7cf39130e1feef76e9e37371b4c Mon Sep 17 00:00:00 2001 From: maxxkim Date: Mon, 25 Dec 2023 17:23:18 +0300 Subject: [PATCH] Added logic for body_circumferences and city_of_living --- .../bloc/body_circumferences_bloc.dart | 6 +- .../bloc/body_circumferences_state.dart | 33 +++++---- .../body_circumferences_screen.dart | 68 ++++++++++++------- .../models/body_circumferences_model.dart | 11 ++- .../bloc/city_of_living_bloc.dart | 3 + .../city_of_living_screen.dart | 44 +++++++----- .../models/city_of_living_model.dart | 8 ++- .../date_of_birth_screen.dart | 39 ++++++----- .../models/date_of_birth_model.dart | 12 +++- .../gender_screen/bloc/gender_bloc.dart | 9 --- lib/widgets/custom_text_form_field.dart | 5 ++ 11 files changed, 147 insertions(+), 91 deletions(-) diff --git a/lib/presentation/body_circumferences_screen/bloc/body_circumferences_bloc.dart b/lib/presentation/body_circumferences_screen/bloc/body_circumferences_bloc.dart index 5b626c60..30e0097c 100644 --- a/lib/presentation/body_circumferences_screen/bloc/body_circumferences_bloc.dart +++ b/lib/presentation/body_circumferences_screen/bloc/body_circumferences_bloc.dart @@ -18,8 +18,8 @@ class BodyCircumferencesBloc Emitter emit, ) async { emit(state.copyWith( - valueController: TextEditingController(), - valueController1: TextEditingController(), - valueController2: TextEditingController())); + chestCircumferenceController: TextEditingController(), + waistCircumferenceController: TextEditingController(), + hipCircumferenceController: TextEditingController())); } } diff --git a/lib/presentation/body_circumferences_screen/bloc/body_circumferences_state.dart b/lib/presentation/body_circumferences_screen/bloc/body_circumferences_state.dart index 9c952fb0..df28755c 100644 --- a/lib/presentation/body_circumferences_screen/bloc/body_circumferences_state.dart +++ b/lib/presentation/body_circumferences_screen/bloc/body_circumferences_state.dart @@ -5,37 +5,40 @@ part of 'body_circumferences_bloc.dart'; /// Represents the state of BodyCircumferences in the application. class BodyCircumferencesState extends Equatable { BodyCircumferencesState({ - this.valueController, - this.valueController1, - this.valueController2, + this.chestCircumferenceController, + this.waistCircumferenceController, + this.hipCircumferenceController, this.bodyCircumferencesModelObj, }); - TextEditingController? valueController; + TextEditingController? chestCircumferenceController; - TextEditingController? valueController1; + TextEditingController? waistCircumferenceController; - TextEditingController? valueController2; + TextEditingController? hipCircumferenceController; BodyCircumferencesModel? bodyCircumferencesModelObj; @override List get props => [ - valueController, - valueController1, - valueController2, + chestCircumferenceController, + waistCircumferenceController, + hipCircumferenceController, bodyCircumferencesModelObj, ]; BodyCircumferencesState copyWith({ - TextEditingController? valueController, - TextEditingController? valueController1, - TextEditingController? valueController2, + TextEditingController? chestCircumferenceController, + TextEditingController? waistCircumferenceController, + TextEditingController? hipCircumferenceController, BodyCircumferencesModel? bodyCircumferencesModelObj, }) { return BodyCircumferencesState( - valueController: valueController ?? this.valueController, - valueController1: valueController1 ?? this.valueController1, - valueController2: valueController2 ?? this.valueController2, + chestCircumferenceController: + chestCircumferenceController ?? this.chestCircumferenceController, + waistCircumferenceController: + waistCircumferenceController ?? this.waistCircumferenceController, + hipCircumferenceController: + hipCircumferenceController ?? this.hipCircumferenceController, bodyCircumferencesModelObj: bodyCircumferencesModelObj ?? this.bodyCircumferencesModelObj, ); diff --git a/lib/presentation/body_circumferences_screen/body_circumferences_screen.dart b/lib/presentation/body_circumferences_screen/body_circumferences_screen.dart index 69b295f7..c6e75bce 100644 --- a/lib/presentation/body_circumferences_screen/body_circumferences_screen.dart +++ b/lib/presentation/body_circumferences_screen/body_circumferences_screen.dart @@ -1,4 +1,5 @@ import 'bloc/body_circumferences_bloc.dart'; +import 'package:flutter/services.dart'; import 'models/body_circumferences_model.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/widgets/app_bar/appbar_leading_image.dart'; @@ -9,25 +10,23 @@ import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_m import 'package:eatvio_app/widgets/custom_text_form_field.dart'; import 'package:flutter/material.dart'; -class BodyCircumferencesScreen extends StatefulWidget { +class BodyCircumferencesScreen extends StatelessWidget { const BodyCircumferencesScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { + final sheet = + ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( create: (context) => BodyCircumferencesBloc(BodyCircumferencesState( - bodyCircumferencesModelObj: BodyCircumferencesModel())) + bodyCircumferencesModelObj: + BodyCircumferencesModel(userRegistrationSheet: sheet))) ..add(BodyCircumferencesInitialEvent()), child: BodyCircumferencesScreen()); } - @override - State createState() => - _BodyCircumferencesScreenState(); -} - -class _BodyCircumferencesScreenState extends State { @override Widget build(BuildContext context) { + final digitsOnly = FilteringTextInputFormatter.digitsOnly; mediaQueryData = MediaQuery.of(context); return SafeArea( child: Scaffold( @@ -63,10 +62,12 @@ class _BodyCircumferencesScreenState extends State { SizedBox(height: 3.v), BlocSelector( - selector: (state) => state.valueController, - builder: (context, valueController) { + selector: (state) => state.chestCircumferenceController, + builder: (context, chestCircumferenceController) { return CustomTextFormField( - controller: valueController, hintText: "90".tr); + inputFormatters: [digitsOnly], + controller: chestCircumferenceController, + hintText: "90".tr); }) ]), SizedBox(height: 19.v), @@ -75,10 +76,12 @@ class _BodyCircumferencesScreenState extends State { SizedBox(height: 5.v), BlocSelector( - selector: (state) => state.valueController1, - builder: (context, valueController1) { + selector: (state) => state.waistCircumferenceController, + builder: (context, waistCircumferenceController) { return CustomTextFormField( - controller: valueController1, hintText: "60".tr); + inputFormatters: [digitsOnly], + controller: waistCircumferenceController, + hintText: "60".tr); }), SizedBox(height: 21.v), Text("hip_circumference".tr, @@ -86,20 +89,39 @@ class _BodyCircumferencesScreenState extends State { SizedBox(height: 3.v), BlocSelector( - selector: (state) => state.valueController2, - builder: (context, valueController2) { + selector: (state) => state.hipCircumferenceController, + builder: (context, hipCircumferenceController) { return CustomTextFormField( - controller: valueController2, + inputFormatters: [digitsOnly], + controller: hipCircumferenceController, hintText: "90".tr, textInputAction: TextInputAction.done); }), Spacer(), - NextStepButton( - text: "continue".tr.toUpperCase(), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: () { - navigateToWeight(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 + .bodyCircumferencesModelObj! + .userRegistrationSheet; + sheet.chestCircumference = int.tryParse( + state.chestCircumferenceController!.text)!; + sheet.waistCircumference = int.tryParse( + state.waistCircumferenceController!.text)!; + sheet.hipCircumference = int.tryParse( + state.hipCircumferenceController!.text)!; + Navigator.pushNamed( + context, + AppRoutes.weightScreen, + arguments: sheet, + ); + }); + }), SizedBox(height: 17.v), ])))); } diff --git a/lib/presentation/body_circumferences_screen/models/body_circumferences_model.dart b/lib/presentation/body_circumferences_screen/models/body_circumferences_model.dart index 3d6dd7c9..880379bd 100644 --- a/lib/presentation/body_circumferences_screen/models/body_circumferences_model.dart +++ b/lib/presentation/body_circumferences_screen/models/body_circumferences_model.dart @@ -1,16 +1,21 @@ // ignore_for_file: must_be_immutable import 'package:equatable/equatable.dart'; +import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart'; /// This class defines the variables used in the [body_circumferences_screen], /// and is typically used to hold data that is passed between different parts of the application. class BodyCircumferencesModel extends Equatable { - BodyCircumferencesModel() {} + UserRegistrationSheet userRegistrationSheet; + BodyCircumferencesModel({required this.userRegistrationSheet}) {} BodyCircumferencesModel copyWith() { - return BodyCircumferencesModel(); + return BodyCircumferencesModel( + userRegistrationSheet: + userRegistrationSheet ?? this.userRegistrationSheet, + ); } @override - List get props => []; + List get props => [userRegistrationSheet]; } diff --git a/lib/presentation/city_of_living_screen/bloc/city_of_living_bloc.dart b/lib/presentation/city_of_living_screen/bloc/city_of_living_bloc.dart index c7cf389f..c0cad702 100644 --- a/lib/presentation/city_of_living_screen/bloc/city_of_living_bloc.dart +++ b/lib/presentation/city_of_living_screen/bloc/city_of_living_bloc.dart @@ -28,6 +28,8 @@ class CityOfLivingBloc extends Bloc { Emitter emit, ) { emit(state.copyWith(selectedDropDownValue: event.value)); + state.cityOfLivingModelObj?.userRegistrationSheet.country = + event.value.title; } _changeDropDown1( @@ -35,6 +37,7 @@ class CityOfLivingBloc extends Bloc { Emitter emit, ) { emit(state.copyWith(selectedDropDownValue1: event.value)); + state.cityOfLivingModelObj?.userRegistrationSheet.city = event.value.title; } List fillDropdownItemList() { diff --git a/lib/presentation/city_of_living_screen/city_of_living_screen.dart b/lib/presentation/city_of_living_screen/city_of_living_screen.dart index 4fa7da61..2f2e8655 100644 --- a/lib/presentation/city_of_living_screen/city_of_living_screen.dart +++ b/lib/presentation/city_of_living_screen/city_of_living_screen.dart @@ -13,9 +13,12 @@ class CityOfLivingScreen extends StatelessWidget { const CityOfLivingScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { + final sheet = + ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => CityOfLivingBloc( - CityOfLivingState(cityOfLivingModelObj: CityOfLivingModel())) + create: (context) => CityOfLivingBloc(CityOfLivingState( + cityOfLivingModelObj: + CityOfLivingModel(userRegistrationSheet: sheet))) ..add(CityOfLivingInitialEvent()), child: CityOfLivingScreen()); } @@ -47,7 +50,8 @@ class CityOfLivingScreen extends StatelessWidget { valueColor: AlwaysStoppedAnimation( appTheme.blueA400)))), SizedBox(height: 39.v), - Text("Moscow".tr, style: theme.textTheme.headlineSmall), + Text("place_of_living".tr, + style: theme.textTheme.headlineSmall), Spacer(flex: 34), Text("country".tr, style: theme.textTheme.bodyLarge), SizedBox(height: 2.v), @@ -65,7 +69,7 @@ class CityOfLivingScreen extends StatelessWidget { imagePath: ImageConstant.imgFavorite, height: 12.adaptSize, width: 12.adaptSize)), - hintText: "Russia".tr, + hintText: "Не выбрано".tr, items: cityOfLivingModelObj?.dropdownItemList ?? [], onChanged: (value) { context @@ -90,7 +94,7 @@ class CityOfLivingScreen extends StatelessWidget { imagePath: ImageConstant.imgFavorite, height: 12.adaptSize, width: 12.adaptSize)), - hintText: "Moscow".tr, + hintText: "Не выбрано".tr, items: cityOfLivingModelObj?.dropdownItemList1 ?? [], onChanged: (value) { @@ -100,12 +104,23 @@ class CityOfLivingScreen extends StatelessWidget { }); }), Spacer(flex: 65), - NextStepButton( - text: "continue".tr.toUpperCase(), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: () { - navigateToCircumferences(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.cityOfLivingModelObj!.userRegistrationSheet; + Navigator.pushNamed( + context, + AppRoutes.bodyCircumferencesScreen, + arguments: sheet, + ); + }); + }), SizedBox(height: 17.v), ])))); } @@ -128,11 +143,4 @@ class CityOfLivingScreen extends StatelessWidget { onTapArrowLeft(BuildContext context) { NavigatorService.goBack(); } - - /// Navigates to the bodyCircumferencesScreen when the action is triggered. - navigateToCircumferences(BuildContext context) { - NavigatorService.pushNamed( - AppRoutes.bodyCircumferencesScreen, - ); - } } diff --git a/lib/presentation/city_of_living_screen/models/city_of_living_model.dart b/lib/presentation/city_of_living_screen/models/city_of_living_model.dart index a20b013c..25c3dec7 100644 --- a/lib/presentation/city_of_living_screen/models/city_of_living_model.dart +++ b/lib/presentation/city_of_living_screen/models/city_of_living_model.dart @@ -2,11 +2,14 @@ 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 [city_of_living_screen], /// and is typically used to hold data that is passed between different parts of the application. class CityOfLivingModel extends Equatable { + UserRegistrationSheet userRegistrationSheet; CityOfLivingModel({ + required this.userRegistrationSheet, this.dropdownItemList = const [], this.dropdownItemList1 = const [], }) {} @@ -20,11 +23,14 @@ class CityOfLivingModel extends Equatable { List? dropdownItemList1, }) { return CityOfLivingModel( + userRegistrationSheet: + userRegistrationSheet ?? this.userRegistrationSheet, dropdownItemList: dropdownItemList ?? this.dropdownItemList, dropdownItemList1: dropdownItemList1 ?? this.dropdownItemList1, ); } @override - List get props => [dropdownItemList, dropdownItemList1]; + List get props => + [dropdownItemList, dropdownItemList1, userRegistrationSheet]; } diff --git a/lib/presentation/date_of_birth_screen/date_of_birth_screen.dart b/lib/presentation/date_of_birth_screen/date_of_birth_screen.dart index d542bebf..5c3dcb6e 100644 --- a/lib/presentation/date_of_birth_screen/date_of_birth_screen.dart +++ b/lib/presentation/date_of_birth_screen/date_of_birth_screen.dart @@ -12,9 +12,12 @@ class DateOfBirthScreen extends StatefulWidget { const DateOfBirthScreen({Key? key}) : super(key: key); static Widget builder(BuildContext context) { + final sheet = + ModalRoute.of(context)!.settings.arguments as UserRegistrationSheet; return BlocProvider( - create: (context) => DateOfBirthBloc( - DateOfBirthState(dateOfBirthModelObj: DateOfBirthModel())) + create: (context) => DateOfBirthBloc(DateOfBirthState( + dateOfBirthModelObj: + DateOfBirthModel(userRegistrationSheet: sheet))) ..add(DateOfBirthInitialEvent()), child: DateOfBirthScreen()); } @@ -59,12 +62,24 @@ class _DateOfBirthScreenState extends State { Spacer(flex: 39), _buildDateInput(context), Spacer(flex: 60), - NextStepButton( - text: "continue".tr.toUpperCase(), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - onPressed: () { - navigateToCity(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 + .dateOfBirthModelObj!.userRegistrationSheet; + sheet.birthdate = selectedDate; + Navigator.pushNamed( + context, + AppRoutes.cityOfLivingScreen, + arguments: sheet, + ); + }); + }), SizedBox(height: 17.v), ])))); }); @@ -124,7 +139,6 @@ class _DateOfBirthScreenState extends State { /// /// This function returns a `Future` that completes with `void`. Future openDatePickerDialog(BuildContext context) async { - var initialState = BlocProvider.of(context).state; DateTime? dateTime = await showDatePicker( context: context, initialDate: DateTime.now(), @@ -137,11 +151,4 @@ class _DateOfBirthScreenState extends State { }); } } - - /// Navigates to the cityOfLivingScreen when the action is triggered. - navigateToCity(BuildContext context) { - NavigatorService.pushNamed( - AppRoutes.cityOfLivingScreen, - ); - } } diff --git a/lib/presentation/date_of_birth_screen/models/date_of_birth_model.dart b/lib/presentation/date_of_birth_screen/models/date_of_birth_model.dart index 3cc83943..17bae696 100644 --- a/lib/presentation/date_of_birth_screen/models/date_of_birth_model.dart +++ b/lib/presentation/date_of_birth_screen/models/date_of_birth_model.dart @@ -1,16 +1,22 @@ // ignore_for_file: must_be_immutable import 'package:equatable/equatable.dart'; +import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart'; /// This class defines the variables used in the [date_of_birth_screen], /// and is typically used to hold data that is passed between different parts of the application. class DateOfBirthModel extends Equatable { - DateOfBirthModel() {} + UserRegistrationSheet userRegistrationSheet; + + DateOfBirthModel({required this.userRegistrationSheet}) {} DateOfBirthModel copyWith() { - return DateOfBirthModel(); + return DateOfBirthModel( + userRegistrationSheet: + userRegistrationSheet ?? this.userRegistrationSheet, + ); } @override - List get props => []; + List get props => [userRegistrationSheet]; } diff --git a/lib/presentation/gender_screen/bloc/gender_bloc.dart b/lib/presentation/gender_screen/bloc/gender_bloc.dart index b30f421a..112cab6e 100644 --- a/lib/presentation/gender_screen/bloc/gender_bloc.dart +++ b/lib/presentation/gender_screen/bloc/gender_bloc.dart @@ -25,14 +25,5 @@ class GenderBloc extends Bloc { ) { emit(state.copyWith(selectedRadioValue: event.value)); state.genderModelObj?.userRegistrationSheet.gender = event.value; - /* - print(state.genderModelObj?.userRegistrationSheet.lang); - print(state.genderModelObj?.userRegistrationSheet.email); - print(state.genderModelObj?.userRegistrationSheet.password); - print(state.genderModelObj?.userRegistrationSheet.passwordConfirmation); - print(state.genderModelObj?.userRegistrationSheet.firstName); - print(state.genderModelObj?.userRegistrationSheet.lastName); - print(state.genderModelObj?.userRegistrationSheet.gender); - */ } } diff --git a/lib/widgets/custom_text_form_field.dart b/lib/widgets/custom_text_form_field.dart index 95883776..00bfdf3c 100644 --- a/lib/widgets/custom_text_form_field.dart +++ b/lib/widgets/custom_text_form_field.dart @@ -1,5 +1,6 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; class CustomTextFormField extends StatelessWidget { CustomTextFormField({ @@ -21,6 +22,7 @@ class CustomTextFormField extends StatelessWidget { this.suffix, this.suffixConstraints, this.contentPadding, + this.inputFormatters, this.borderDecoration, this.fillColor, this.filled = true, @@ -44,6 +46,8 @@ class CustomTextFormField extends StatelessWidget { final bool? obscureText; + final List? inputFormatters; + final TextInputAction? textInputAction; final TextInputType? textInputType; @@ -98,6 +102,7 @@ class CustomTextFormField extends StatelessWidget { decoration: decoration, validator: validator, onSaved: onSaved, + inputFormatters: inputFormatters, ), ); InputDecoration get decoration => InputDecoration(