refactor(registration): Height and weight are now inputs instead of DropDowns

This commit is contained in:
2024-04-16 14:11:55 +03:00
parent 8f84f15977
commit 3a383dac6f
8 changed files with 202 additions and 238 deletions

View File

@@ -9,7 +9,6 @@ part 'height_state.dart';
class HeightBloc extends Bloc<HeightEvent, HeightState> {
HeightBloc(HeightState initialState) : super(initialState) {
on<HeightInitialEvent>(_onInitialize);
on<ChangeDropDownEvent>(_changeDropDown);
}
_onInitialize(
@@ -17,25 +16,7 @@ class HeightBloc extends Bloc<HeightEvent, HeightState> {
Emitter<HeightState> emit,
) async {
emit(state.copyWith(
heightModelObj: state.heightModelObj
?.copyWith(dropdownItemList: fillDropdownItemList())));
}
_changeDropDown(
ChangeDropDownEvent event,
Emitter<HeightState> emit,
) {
emit(state.copyWith(selectedDropDownValue: event.value));
state.heightModelObj?.userRegistrationSheet.height = event.value.title;
}
List<SelectionPopupModel> fillDropdownItemList() {
List<SelectionPopupModel> selectionPopupModels = [];
for (int i = 140; i <= 220; i++) {
selectionPopupModels
.add(SelectionPopupModel(id: i - 34, title: i.toString()));
}
return selectionPopupModels;
heightModelObj: state.heightModelObj?.copyWith(),
heightController: state.heightController));
}
}

View File

@@ -14,15 +14,3 @@ class HeightInitialEvent extends HeightEvent {
@override
List<Object?> get props => [];
}
///event for dropdown selection
class ChangeDropDownEvent extends HeightEvent {
ChangeDropDownEvent({required this.value});
SelectionPopupModel value;
@override
List<Object?> get props => [
value,
];
}

View File

@@ -5,26 +5,25 @@ part of 'height_bloc.dart';
/// Represents the state of Height in the application.
class HeightState extends Equatable {
HeightState({
this.selectedDropDownValue,
this.heightController,
this.heightModelObj,
});
SelectionPopupModel? selectedDropDownValue;
TextEditingController? heightController;
HeightModel? heightModelObj;
@override
List<Object?> get props => [
selectedDropDownValue,
heightController,
heightModelObj,
];
HeightState copyWith({
SelectionPopupModel? selectedDropDownValue,
TextEditingController? heightController,
HeightModel? heightModelObj,
}) {
return HeightState(
selectedDropDownValue:
selectedDropDownValue ?? this.selectedDropDownValue,
heightController: heightController ?? this.heightController,
heightModelObj: heightModelObj ?? this.heightModelObj,
);
}

View File

@@ -4,12 +4,13 @@ import 'package:eatvio_app/core/app_export.dart';
import 'package:eatvio_app/widgets/app_bar/appbar_leading_image.dart';
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/custom_text_form_field.dart';
import 'package:flutter/services.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 HeightScreen extends StatefulWidget {
class HeightScreen extends StatelessWidget {
const HeightScreen({Key? key}) : super(key: key);
static Widget builder(BuildContext context) {
@@ -22,82 +23,91 @@ class HeightScreen extends StatefulWidget {
child: HeightScreen());
}
@override
State<HeightScreen> createState() => _HeightScreenState();
}
class _HeightScreenState extends State<HeightScreen> {
@override
Widget build(BuildContext context) {
mediaQueryData = MediaQuery.of(context);
return SafeArea(
child: Scaffold(
appBar: _buildAppBar(context),
body: Container(
width: double.maxFinite,
padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v),
child: Column(children: [
SizedBox(height: 7.v),
Container(
height: 16.v,
width: 343.h,
decoration: BoxDecoration(
color: theme.colorScheme.onPrimary,
borderRadius: BorderRadius.circular(8.h),
border: Border.all(
color: theme.colorScheme.primary, width: 1.h)),
child: ClipRRect(
borderRadius: BorderRadius.circular(8.h),
child: LinearProgressIndicator(
value: 0.55,
backgroundColor: theme.colorScheme.onPrimary,
valueColor: AlwaysStoppedAnimation<Color>(
appTheme.blueA400)))),
SizedBox(height: 39.v),
Column(children: [
Text("height_measurements".tr,
style: theme.textTheme.headlineSmall),
SizedBox(height: 174.v),
Column(children: [
Text("your_height".tr, style: theme.textTheme.bodyLarge),
child: Scaffold(
appBar: _buildAppBar(context),
body: Container(
width: double.maxFinite,
padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v),
child: Column(
children: [
SizedBox(height: 7.v),
Container(
height: 16.v,
width: 343.h,
decoration: BoxDecoration(
color: theme.colorScheme.onPrimary,
borderRadius: BorderRadius.circular(8.h),
border: Border.all(
color: theme.colorScheme.primary,
width: 1.h,
),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(8.h),
child: LinearProgressIndicator(
value: 0.55,
backgroundColor: theme.colorScheme.onPrimary,
valueColor: AlwaysStoppedAnimation<Color>(
appTheme.blueA400,
),
),
),
),
SizedBox(height: 39.v),
Column(
children: [
Text(
"height_measurements".tr,
style: theme.textTheme.headlineSmall,
),
SizedBox(height: 174.v),
Column(
children: [
Text(
"your_height".tr,
style: theme.textTheme.bodyLarge,
),
SizedBox(height: 4.v),
BlocSelector<HeightBloc, HeightState, HeightModel?>(
selector: (state) => state.heightModelObj,
builder: (context, heightModelObj) {
return CustomDropDown(
icon: Container(
margin: EdgeInsets.fromLTRB(
30.h, 11.v, 17.h, 11.v),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(1.h)),
child: CustomImageView(
imagePath: ImageConstant.imgFavorite,
height: 12.adaptSize,
width: 12.adaptSize)),
hintText: "170",
items: heightModelObj?.dropdownItemList ?? [],
onChanged: newMethod(context));
})
])
]),
Spacer(),
BlocBuilder<HeightBloc, HeightState>(
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: onTapNext(state, context));
}),
]))));
}
newMethod(BuildContext context) {
return (value) {
context.read<HeightBloc>().add(ChangeDropDownEvent(value: value));
};
BlocBuilder<HeightBloc, HeightState>(
builder: (context, state) {
return CustomTextFormField(
width: 150.h,
textInputAction: TextInputAction.done,
controller: state.heightController,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly,
],
);
})
],
),
],
),
Spacer(),
BlocBuilder<HeightBloc, HeightState>(
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: onTapNext(state, context),
);
},
),
],
),
),
),
);
}
onTapNext(HeightState state, BuildContext context) {

View File

@@ -9,7 +9,6 @@ part 'weight_state.dart';
class WeightBloc extends Bloc<WeightEvent, WeightState> {
WeightBloc(WeightState initialState) : super(initialState) {
on<WeightInitialEvent>(_onInitialize);
on<ChangeDropDownEvent>(_changeDropDown);
}
_onInitialize(
@@ -17,25 +16,7 @@ class WeightBloc extends Bloc<WeightEvent, WeightState> {
Emitter<WeightState> emit,
) async {
emit(state.copyWith(
weightModelObj: state.weightModelObj
?.copyWith(dropdownItemList: fillDropdownItemList())));
}
_changeDropDown(
ChangeDropDownEvent event,
Emitter<WeightState> emit,
) {
emit(state.copyWith(selectedDropDownValue: event.value));
state.weightModelObj?.userRegistrationSheet.weight = event.value.title;
}
List<SelectionPopupModel> fillDropdownItemList() {
List<SelectionPopupModel> selectionPopupModels = [];
for (int i = 35; i <= 200; i++) {
selectionPopupModels
.add(SelectionPopupModel(id: i - 34, title: i.toString()));
}
return selectionPopupModels;
weightModelObj: state.weightModelObj?.copyWith(),
weightController: state.weightController));
}
}

View File

@@ -14,15 +14,3 @@ class WeightInitialEvent extends WeightEvent {
@override
List<Object?> get props => [];
}
///event for dropdown selection
class ChangeDropDownEvent extends WeightEvent {
ChangeDropDownEvent({required this.value});
SelectionPopupModel value;
@override
List<Object?> get props => [
value,
];
}

View File

@@ -5,26 +5,25 @@ part of 'weight_bloc.dart';
/// Represents the state of Weight in the application.
class WeightState extends Equatable {
WeightState({
this.selectedDropDownValue,
this.weightController,
this.weightModelObj,
});
SelectionPopupModel? selectedDropDownValue;
TextEditingController? weightController;
WeightModel? weightModelObj;
@override
List<Object?> get props => [
selectedDropDownValue,
weightController,
weightModelObj,
];
WeightState copyWith({
SelectionPopupModel? selectedDropDownValue,
TextEditingController? weightController,
WeightModel? weightModelObj,
}) {
return WeightState(
selectedDropDownValue:
selectedDropDownValue ?? this.selectedDropDownValue,
weightController: weightController ?? this.weightController,
weightModelObj: weightModelObj ?? this.weightModelObj,
);
}

View File

@@ -4,12 +4,13 @@ import 'package:eatvio_app/core/app_export.dart';
import 'package:eatvio_app/widgets/app_bar/appbar_leading_image.dart';
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/custom_text_form_field.dart';
import 'package:flutter/services.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 {
class WeightScreen extends StatelessWidget {
const WeightScreen({Key? key}) : super(key: key);
static Widget builder(BuildContext context) {
@@ -22,96 +23,94 @@ class WeightScreen extends StatefulWidget {
child: WeightScreen());
}
@override
State<WeightScreen> createState() => _WeightScreenState();
}
class _WeightScreenState extends State<WeightScreen> {
@override
Widget build(BuildContext context) {
mediaQueryData = MediaQuery.of(context);
return SafeArea(
child: Scaffold(
appBar: _buildAppBar(context),
body: Container(
width: double.maxFinite,
padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v),
child: Column(children: [
SizedBox(height: 7.v),
Container(
height: 16.v,
width: 343.h,
decoration: BoxDecoration(
color: theme.colorScheme.onPrimary,
borderRadius: BorderRadius.circular(8.h),
border: Border.all(
color: theme.colorScheme.primary, width: 1.h)),
child: ClipRRect(
borderRadius: BorderRadius.circular(8.h),
child: LinearProgressIndicator(
value: 0.48,
backgroundColor: theme.colorScheme.onPrimary,
valueColor: AlwaysStoppedAnimation<Color>(
appTheme.blueA400)))),
SizedBox(height: 39.v),
Column(children: [
Text("weight_measurements".tr,
style: theme.textTheme.headlineSmall),
SizedBox(height: 174.v),
Column(children: [
Text("your_weight".tr, style: theme.textTheme.bodyLarge),
child: Scaffold(
appBar: _buildAppBar(context),
body: Container(
width: double.maxFinite,
padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v),
child: Column(
children: [
SizedBox(height: 7.v),
Container(
height: 16.v,
width: 343.h,
decoration: BoxDecoration(
color: theme.colorScheme.onPrimary,
borderRadius: BorderRadius.circular(8.h),
border: Border.all(
color: theme.colorScheme.primary,
width: 1.h,
),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(8.h),
child: LinearProgressIndicator(
value: 0.55,
backgroundColor: theme.colorScheme.onPrimary,
valueColor: AlwaysStoppedAnimation<Color>(
appTheme.blueA400,
),
),
),
),
SizedBox(height: 39.v),
Column(
children: [
Text(
"weight_measurements".tr,
style: theme.textTheme.headlineSmall,
),
SizedBox(height: 174.v),
Column(
children: [
Text(
"your_weight".tr,
style: theme.textTheme.bodyLarge,
),
SizedBox(height: 4.v),
BlocSelector<WeightBloc, WeightState, WeightModel?>(
selector: (state) => state.weightModelObj,
builder: (context, weightModelObj) {
return CustomDropDown(
icon: Container(
margin: EdgeInsets.fromLTRB(
30.h, 11.v, 17.h, 11.v),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(1.h)),
child: CustomImageView(
imagePath: ImageConstant.imgFavorite,
height: 12.adaptSize,
width: 12.adaptSize)),
hintText: "Не выбрано",
items: weightModelObj?.dropdownItemList ?? [],
onChanged: _onDropDownChanged);
})
])
]),
Spacer(),
BlocBuilder<WeightBloc, WeightState>(
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: onTapNext(context, state));
}),
]))));
BlocBuilder<WeightBloc, WeightState>(
builder: (context, state) {
return CustomTextFormField(
width: 150.h,
textInputAction: TextInputAction.done,
controller: state.weightController,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly,
],
);
})
],
),
],
),
Spacer(),
BlocBuilder<WeightBloc, WeightState>(
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: onTapNext(state, context),
);
},
),
],
),
),
),
);
}
/// Section Widget
_buildAppBar(BuildContext context) {
return CustomAppBar(
leadingWidth: 29.h,
leading: AppbarLeadingImage(
imagePath: ImageConstant.imgArrowLeft,
margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v),
onTap: () => onTapArrowLeft(context)),
centerTitle: true,
title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio));
}
/// Navigates to the previous screen.
onTapArrowLeft(BuildContext context) {
NavigatorService.goBack();
}
onTapNext(BuildContext context, WeightState state) {
onTapNext(WeightState state, BuildContext context) {
return () {
UserRegistrationSheet sheet = state.weightModelObj!.userRegistrationSheet;
Navigator.pushNamed(
@@ -122,7 +121,26 @@ class _WeightScreenState extends State<WeightScreen> {
};
}
void _onDropDownChanged(value) {
context.read<WeightBloc>().add(ChangeDropDownEvent(value: value));
/// Section Widget
_buildAppBar(BuildContext context) {
return CustomAppBar(
leadingWidth: 29.h,
leading: AppbarLeadingImage(
imagePath: ImageConstant.imgArrowLeft,
margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v),
onTap: onTapBack(context)),
centerTitle: true,
title: AppbarTitleImage(imagePath: ImageConstant.imgLogoEatvio));
}
Function onTapBack(BuildContext context) {
return () {
onTapArrowLeft(context);
};
}
/// Navigates to the previous screen.
onTapArrowLeft(BuildContext context) {
NavigatorService.goBack();
}
}