forked from eatvio/eatvio_app
Finished client-side calidation
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
//import 'package:eatvio_app/core/app_export.dart';
|
||||
|
||||
class ApiClient {}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class UserRegistrationSheet {
|
||||
String name;
|
||||
String firstName;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'ru/ru_translations.dart';
|
||||
import 'en_us/en_us_translations.dart';
|
||||
//import 'en_us/en_us_translations.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import '../core/app_export.dart';
|
||||
@@ -9,10 +9,12 @@ class AppLocalization {
|
||||
|
||||
Locale locale;
|
||||
|
||||
static final Map<String, Map<String, String>> _localizedValues = {'ru': ru};
|
||||
static final Map<String, Map<String, String>> __localizedValues = {
|
||||
'en': enUs
|
||||
static final Map<String, Map<String, String>> _localizedValues = {
|
||||
'ru': ru,
|
||||
};
|
||||
/*static final Map<String, Map<String, String>> __localizedValues = {
|
||||
'en': enUs
|
||||
};*/
|
||||
|
||||
static AppLocalization of() {
|
||||
return Localizations.of<AppLocalization>(
|
||||
|
||||
@@ -18,7 +18,7 @@ final Map<String, String> ru = {
|
||||
"place_of_living": "Место проживания",
|
||||
|
||||
// body_circumferences Screen
|
||||
"hip_circumference": "Обхват бедр", "chest_circumference": "Обхват груди",
|
||||
"hip_circumference": "Обхват бедер", "chest_circumference": "Обхват груди",
|
||||
"waist_circumference": "Обхват талии",
|
||||
"initial_measurements": "Первичные замеры",
|
||||
|
||||
@@ -87,4 +87,16 @@ final Map<String, String> ru = {
|
||||
"password_confirmation_mismatch": "Пароли не совпадают",
|
||||
|
||||
// Name
|
||||
"first_name_empty": "Имя обязательно для заполнения",
|
||||
"first_name_short": "В имени должен быть минимум 1 символ",
|
||||
"last_name_empty": "Фамилия обязательна для заполнения",
|
||||
"last_name_short": "В фамилии должен быть минимум 6 символов",
|
||||
|
||||
// Body Circumference
|
||||
"circumference_empty": "Все замеры обязательны к заполнению",
|
||||
"circumference_is_not_a_number": "Все замеры должны быть числами",
|
||||
|
||||
// Body Circumference
|
||||
"pressure_empty": "Все показатели давления обязательны к заполнению",
|
||||
"pressure_is_not_a_number": "Все показатели давления должны быть числами",
|
||||
};
|
||||
|
||||
@@ -11,8 +11,7 @@ class AdditionalInformationModel extends Equatable {
|
||||
|
||||
AdditionalInformationModel copyWith() {
|
||||
return AdditionalInformationModel(
|
||||
userRegistrationSheet:
|
||||
userRegistrationSheet ?? this.userRegistrationSheet,
|
||||
userRegistrationSheet: userRegistrationSheet,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class _AllergiesScreenState extends State<AllergiesScreen> {
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8.h),
|
||||
child: LinearProgressIndicator(
|
||||
value: 0.62,
|
||||
value: 0.76,
|
||||
backgroundColor: theme.colorScheme.onPrimary,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
appTheme.blueA400)))),
|
||||
|
||||
@@ -11,8 +11,7 @@ class AllergiesModel extends Equatable {
|
||||
|
||||
AllergiesModel copyWith() {
|
||||
return AllergiesModel(
|
||||
userRegistrationSheet:
|
||||
userRegistrationSheet ?? this.userRegistrationSheet,
|
||||
userRegistrationSheet: userRegistrationSheet,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ class _BloodPressureScreenState extends State<BloodPressureScreen> {
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8.h),
|
||||
child: LinearProgressIndicator(
|
||||
value: 0.76,
|
||||
value: 0.62,
|
||||
backgroundColor: theme.colorScheme.onPrimary,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
appTheme.blueA400))))),
|
||||
@@ -175,17 +175,44 @@ class _BloodPressureScreenState extends State<BloodPressureScreen> {
|
||||
left: 16.h, right: 16.h, bottom: 50.v),
|
||||
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||
onPressed: () {
|
||||
UserRegistrationSheet sheet = state
|
||||
.bloodPressureModelObj!.userRegistrationSheet;
|
||||
sheet.bloodPressureUp =
|
||||
state.upPressureController!.text;
|
||||
sheet.bloodPressureDown =
|
||||
state.downPressureController!.text;
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.favoriteSportsScreen,
|
||||
arguments: sheet,
|
||||
);
|
||||
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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
}),
|
||||
BlocBuilder<BloodPressureBloc, BloodPressureState>(
|
||||
@@ -196,7 +223,7 @@ class _BloodPressureScreenState extends State<BloodPressureScreen> {
|
||||
state.bloodPressureModelObj!.userRegistrationSheet;
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.favoriteSportsScreen,
|
||||
AppRoutes.allergiesScreen,
|
||||
arguments: sheet,
|
||||
);
|
||||
},
|
||||
@@ -225,10 +252,21 @@ class _BloodPressureScreenState extends State<BloodPressureScreen> {
|
||||
NavigatorService.goBack();
|
||||
}
|
||||
|
||||
/// Navigates to the favoriteSportsScreen when the action is triggered.
|
||||
navigateToSports(BuildContext context) {
|
||||
NavigatorService.pushNamed(
|
||||
AppRoutes.favoriteSportsScreen,
|
||||
);
|
||||
List<String> validateFields(
|
||||
String bloodPressureUp,
|
||||
String bloodPressureDown,
|
||||
) {
|
||||
List<String> errors = [];
|
||||
|
||||
if (bloodPressureUp.isEmpty | bloodPressureDown.isEmpty) {
|
||||
errors.add('pressure_empty'.tr);
|
||||
}
|
||||
|
||||
if (![bloodPressureUp, bloodPressureDown]
|
||||
.every((pressure) => int.tryParse(pressure) != null)) {
|
||||
errors.add('pressure_is_not_a_number'.tr);
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,20 +106,48 @@ class BodyCircumferencesScreen extends StatelessWidget {
|
||||
left: 16.h, right: 16.h, bottom: 50.v),
|
||||
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||
onPressed: () {
|
||||
UserRegistrationSheet sheet = state
|
||||
.bodyCircumferencesModelObj!
|
||||
.userRegistrationSheet;
|
||||
sheet.chestCircumference =
|
||||
state.chestCircumferenceController!.text!;
|
||||
sheet.waistCircumference =
|
||||
state.waistCircumferenceController!.text!;
|
||||
sheet.hipCircumference =
|
||||
state.hipCircumferenceController!.text!;
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.weightScreen,
|
||||
arguments: sheet,
|
||||
);
|
||||
List<String> errors = validateFields(
|
||||
state.chestCircumferenceController!.text,
|
||||
state.waistCircumferenceController!.text,
|
||||
state.hipCircumferenceController!.text);
|
||||
if (errors.isEmpty) {
|
||||
UserRegistrationSheet sheet = state
|
||||
.bodyCircumferencesModelObj!
|
||||
.userRegistrationSheet;
|
||||
sheet.chestCircumference =
|
||||
state.chestCircumferenceController!.text;
|
||||
sheet.waistCircumference =
|
||||
state.waistCircumferenceController!.text;
|
||||
sheet.hipCircumference =
|
||||
state.hipCircumferenceController!.text;
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.weightScreen,
|
||||
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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
}),
|
||||
]))));
|
||||
@@ -150,4 +178,25 @@ class BodyCircumferencesScreen extends StatelessWidget {
|
||||
AppRoutes.weightScreen,
|
||||
);
|
||||
}
|
||||
|
||||
List<String> validateFields(
|
||||
String chestCircumference,
|
||||
String waistCircumference,
|
||||
String hipCircumference,
|
||||
) {
|
||||
List<String> errors = [];
|
||||
|
||||
if (chestCircumference.isEmpty |
|
||||
waistCircumference.isEmpty |
|
||||
hipCircumference.isEmpty) {
|
||||
errors.add('circumference_empty'.tr);
|
||||
}
|
||||
|
||||
if (![chestCircumference, waistCircumference, hipCircumference]
|
||||
.every((circumference) => int.tryParse(circumference) != null)) {
|
||||
errors.add('circumference_is_not_a_number'.tr);
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ class BodyCircumferencesModel extends Equatable {
|
||||
|
||||
BodyCircumferencesModel copyWith() {
|
||||
return BodyCircumferencesModel(
|
||||
userRegistrationSheet:
|
||||
userRegistrationSheet ?? this.userRegistrationSheet,
|
||||
userRegistrationSheet: userRegistrationSheet,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ class CityOfLivingModel extends Equatable {
|
||||
List<SelectionPopupModel>? dropdownItemList1,
|
||||
}) {
|
||||
return CityOfLivingModel(
|
||||
userRegistrationSheet:
|
||||
userRegistrationSheet ?? this.userRegistrationSheet,
|
||||
userRegistrationSheet: userRegistrationSheet,
|
||||
dropdownItemList: dropdownItemList ?? this.dropdownItemList,
|
||||
dropdownItemList1: dropdownItemList1 ?? this.dropdownItemList1,
|
||||
);
|
||||
|
||||
@@ -12,8 +12,7 @@ class DateOfBirthModel extends Equatable {
|
||||
|
||||
DateOfBirthModel copyWith() {
|
||||
return DateOfBirthModel(
|
||||
userRegistrationSheet:
|
||||
userRegistrationSheet ?? this.userRegistrationSheet,
|
||||
userRegistrationSheet: userRegistrationSheet,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,7 @@ class FavoriteFoodsModel extends Equatable {
|
||||
|
||||
FavoriteFoodsModel copyWith() {
|
||||
return FavoriteFoodsModel(
|
||||
userRegistrationSheet:
|
||||
userRegistrationSheet ?? this.userRegistrationSheet,
|
||||
userRegistrationSheet: userRegistrationSheet,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class _HeightScreenState extends State<HeightScreen> {
|
||||
state.heightModelObj!.userRegistrationSheet;
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.allergiesScreen,
|
||||
AppRoutes.bloodPressureScreen,
|
||||
arguments: sheet,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -83,15 +83,42 @@ class NameScreen extends StatelessWidget {
|
||||
left: 16.h, right: 16.h, bottom: 50.v),
|
||||
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||
onPressed: () {
|
||||
UserRegistrationSheet sheet =
|
||||
state.nameModelObj!.userRegistrationSheet;
|
||||
sheet.firstName = state.firstNameController!.text;
|
||||
sheet.lastName = state.lastNameController!.text;
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.genderScreen,
|
||||
arguments: sheet,
|
||||
);
|
||||
List<String> errors = validateFields(
|
||||
state.firstNameController!.text,
|
||||
state.lastNameController!.text);
|
||||
if (errors.isEmpty) {
|
||||
UserRegistrationSheet sheet =
|
||||
state.nameModelObj!.userRegistrationSheet;
|
||||
sheet.firstName = state.firstNameController!.text;
|
||||
sheet.lastName = state.lastNameController!.text;
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.genderScreen,
|
||||
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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
}),
|
||||
]))));
|
||||
@@ -115,4 +142,29 @@ class NameScreen extends StatelessWidget {
|
||||
onTapArrowLeft(BuildContext context) {
|
||||
NavigatorService.goBack();
|
||||
}
|
||||
|
||||
List<String> validateFields(
|
||||
String firstName,
|
||||
String lastName,
|
||||
) {
|
||||
List<String> errors = [];
|
||||
|
||||
if (firstName.isEmpty) {
|
||||
errors.add('first_name_empty'.tr);
|
||||
}
|
||||
|
||||
if (firstName.length < 1) {
|
||||
errors.add('first_name_short'.tr);
|
||||
}
|
||||
|
||||
if (lastName.isEmpty) {
|
||||
errors.add('last_name_empty'.tr);
|
||||
}
|
||||
|
||||
if (lastName.length < 1) {
|
||||
errors.add('last_name_short'.tr);
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user