forked from eatvio/eatvio_app
refactor(diary): Some more refactoring
This commit is contained in:
@@ -136,11 +136,7 @@ class _BloodPressureScreenState extends State<BloodPressureScreen> {
|
||||
items:
|
||||
bloodPressureModelObj?.dropdownItemList ??
|
||||
[],
|
||||
onChanged: (value) {
|
||||
context
|
||||
.read<BloodPressureBloc>()
|
||||
.add(ChangeHypoDownEvent(value: value));
|
||||
});
|
||||
onChanged: onChangeHyper(context));
|
||||
})),
|
||||
SizedBox(height: 22.v),
|
||||
Text("do_you_have_hypertension_tendency".tr,
|
||||
@@ -167,10 +163,7 @@ class _BloodPressureScreenState extends State<BloodPressureScreen> {
|
||||
items:
|
||||
bloodPressureModelObj?.dropdownItemList ??
|
||||
[],
|
||||
onChanged: (value) {
|
||||
context.read<BloodPressureBloc>().add(
|
||||
ChangeHyperDropDownEvent(value: value));
|
||||
});
|
||||
onChanged: onChangeHypo(context));
|
||||
})),
|
||||
Spacer(),
|
||||
BlocBuilder<BloodPressureBloc, BloodPressureState>(
|
||||
@@ -180,65 +173,88 @@ class _BloodPressureScreenState extends State<BloodPressureScreen> {
|
||||
margin: EdgeInsets.only(
|
||||
left: 16.h, right: 16.h, bottom: 50.v),
|
||||
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||
onPressed: () {
|
||||
List<String> errors = validateFields(
|
||||
state.upPressureController!.text,
|
||||
state.downPressureController!.text);
|
||||
if (errors.isEmpty) {
|
||||
UserRegistrationSheet sheet = state
|
||||
.bloodPressureModelObj!.userRegistrationSheet;
|
||||
sheet.bloodPressureUp =
|
||||
state.upPressureController!.text;
|
||||
sheet.bloodPressureDown =
|
||||
state.downPressureController!.text;
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.favoriteSportsScreen,
|
||||
arguments: sheet,
|
||||
);
|
||||
} else {
|
||||
String errorMessage = '';
|
||||
|
||||
for (var error in errors) {
|
||||
errorMessage += error + '\n\n';
|
||||
}
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Ошибка'),
|
||||
content: Text(errorMessage),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
onPressed: onTapContinue(state, context));
|
||||
}),
|
||||
BlocBuilder<BloodPressureBloc, BloodPressureState>(
|
||||
builder: (context, state) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
UserRegistrationSheet sheet =
|
||||
state.bloodPressureModelObj!.userRegistrationSheet;
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.allergiesScreen,
|
||||
arguments: sheet,
|
||||
);
|
||||
},
|
||||
onTap: onTapSkip(state, context),
|
||||
child: Text("skip".tr, style: theme.textTheme.bodyLarge),
|
||||
);
|
||||
}),
|
||||
]))));
|
||||
}
|
||||
|
||||
onTapSkip(BloodPressureState state, BuildContext context) {
|
||||
return () {
|
||||
UserRegistrationSheet sheet =
|
||||
state.bloodPressureModelObj!.userRegistrationSheet;
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.allergiesScreen,
|
||||
arguments: sheet,
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
onTapContinue(BloodPressureState state, BuildContext context) {
|
||||
return () {
|
||||
List<String> errors = validateFields(
|
||||
state.upPressureController!.text, state.downPressureController!.text);
|
||||
if (errors.isEmpty) {
|
||||
UserRegistrationSheet sheet =
|
||||
state.bloodPressureModelObj!.userRegistrationSheet;
|
||||
sheet.bloodPressureUp = state.upPressureController!.text;
|
||||
sheet.bloodPressureDown = state.downPressureController!.text;
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.favoriteSportsScreen,
|
||||
arguments: sheet,
|
||||
);
|
||||
} else {
|
||||
String errorMessage = '';
|
||||
|
||||
for (var error in errors) {
|
||||
errorMessage += error + '\n\n';
|
||||
}
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Ошибка'),
|
||||
content: Text(errorMessage),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: onTapOK(context),
|
||||
child: Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
onTapOK(BuildContext context) {
|
||||
return () {
|
||||
Navigator.pop(context);
|
||||
};
|
||||
}
|
||||
|
||||
onChangeHypo(BuildContext context) {
|
||||
return (value) {
|
||||
context
|
||||
.read<BloodPressureBloc>()
|
||||
.add(ChangeHyperDropDownEvent(value: value));
|
||||
};
|
||||
}
|
||||
|
||||
onChangeHyper(BuildContext context) {
|
||||
return (value) {
|
||||
context.read<BloodPressureBloc>().add(ChangeHypoDownEvent(value: value));
|
||||
};
|
||||
}
|
||||
|
||||
/// Section Widget
|
||||
_buildAppBar(BuildContext context) {
|
||||
return CustomAppBar(
|
||||
@@ -246,13 +262,17 @@ class _BloodPressureScreenState extends State<BloodPressureScreen> {
|
||||
leading: AppbarLeadingImage(
|
||||
imagePath: ImageConstant.imgArrowLeft,
|
||||
margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v),
|
||||
onTap: () {
|
||||
onTapArrowLeft(context);
|
||||
}),
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user