forked from eatvio/eatvio_app
feat(registration): added api integration for short registration
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/utils/date_time_utils.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
||||
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart';
|
||||
@@ -11,9 +12,35 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:mask_text_input_formatter/mask_text_input_formatter.dart';
|
||||
|
||||
class FirstStepContent extends StatelessWidget {
|
||||
FirstStepContent({super.key});
|
||||
class FirstStepContent extends StatefulWidget {
|
||||
const FirstStepContent({super.key});
|
||||
|
||||
@override
|
||||
State<FirstStepContent> createState() => _FirstStepContentState();
|
||||
}
|
||||
|
||||
class _FirstStepContentState extends State<FirstStepContent> {
|
||||
final maskFormatterForBirthday = MaskTextInputFormatter(mask: '##.##.####', filter: {"#": RegExp(r'[0-9]')}, type: MaskAutoCompletionType.lazy);
|
||||
|
||||
final firstNameController = TextEditingController();
|
||||
|
||||
final lastNameController = TextEditingController();
|
||||
|
||||
final emailController = TextEditingController();
|
||||
|
||||
final phoneController = TextEditingController();
|
||||
|
||||
final dateController = TextEditingController();
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
firstNameController.text = context.read<RegistrationCubitV2>().state.firstName;
|
||||
lastNameController.text = context.read<RegistrationCubitV2>().state.lastName;
|
||||
emailController.text = context.read<RegistrationCubitV2>().state.email;
|
||||
phoneController.text = context.read<RegistrationCubitV2>().state.phone;
|
||||
dateController.text = context.read<RegistrationCubitV2>().state.birthday?.format('dd.MM.yyyy') ?? '';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
@@ -30,7 +57,14 @@ class FirstStepContent extends StatelessWidget {
|
||||
children: [
|
||||
Text(s.first_name, style: TextStyles.textSMedium.copyWith(color: appTheme.black)),
|
||||
const SizedBox(height: 4),
|
||||
CustomTextFormField(hintText: s.your_name, hasError: !state.isFirstNameValid),
|
||||
CustomTextFormField(
|
||||
hintText: s.your_name,
|
||||
hasError: !state.isFirstNameValid,
|
||||
controller: firstNameController,
|
||||
onChanged: (val) {
|
||||
context.read<RegistrationCubitV2>().setFirstName(val);
|
||||
},
|
||||
),
|
||||
if (!state.isFirstNameValid) ...[const SizedBox(height: 4), ValidationErrorWidget(error: s.first_name_validation_error)],
|
||||
],
|
||||
),
|
||||
@@ -42,7 +76,14 @@ class FirstStepContent extends StatelessWidget {
|
||||
children: [
|
||||
Text(s.last_name, style: TextStyles.textSMedium.copyWith(color: appTheme.black)),
|
||||
const SizedBox(height: 4),
|
||||
CustomTextFormField(hintText: s.your_last_name, hasError: !state.isLastNameValid),
|
||||
CustomTextFormField(
|
||||
hintText: s.your_last_name,
|
||||
hasError: !state.isLastNameValid,
|
||||
controller: lastNameController,
|
||||
onChanged: (val) {
|
||||
context.read<RegistrationCubitV2>().setLastName(val);
|
||||
},
|
||||
),
|
||||
if (!state.isLastNameValid) ...[const SizedBox(height: 4), ValidationErrorWidget(error: s.last_name_error)],
|
||||
],
|
||||
),
|
||||
@@ -51,11 +92,36 @@ class FirstStepContent extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(s.email, style: TextStyles.textSMedium.copyWith(color: appTheme.black)),
|
||||
CustomTextFormField(hintText: s.type_email, hasError: !state.isEmailValid),
|
||||
if (!state.isEmailValid) ...[const SizedBox(height: 4), ValidationErrorWidget(error: s.email_error)],
|
||||
CustomTextFormField(
|
||||
hintText: s.type_email,
|
||||
hasError: !state.isEmailValid,
|
||||
controller: emailController,
|
||||
onChanged: (val) {
|
||||
context.read<RegistrationCubitV2>().setEmail(val);
|
||||
},
|
||||
),
|
||||
if (!state.isEmailValid) ...[
|
||||
const SizedBox(height: 4),
|
||||
ValidationErrorWidget(error: state.emailDisplayError.isEmpty ? s.email_error : state.emailDisplayError),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
Text(s.phone, style: TextStyles.textSMedium.copyWith(color: appTheme.black)),
|
||||
const CustomTextFormField(hintText: '+7 (999) 999 99 99'),
|
||||
Column(
|
||||
children: [
|
||||
CustomTextFormField(
|
||||
hintText: '+7 (999) 999 99 99',
|
||||
controller: phoneController,
|
||||
hasError: !state.isPhoneValid,
|
||||
onChanged: (val) {
|
||||
context.read<RegistrationCubitV2>().setPhone(val);
|
||||
},
|
||||
),
|
||||
if (!state.isPhoneValid) ...[
|
||||
const SizedBox(height: 4),
|
||||
ValidationErrorWidget(error: state.phoneDisplayError.isEmpty ? s.phone_error : state.phoneDisplayError),
|
||||
],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -72,8 +138,18 @@ class FirstStepContent extends StatelessWidget {
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: [maskFormatterForBirthday],
|
||||
hasError: !state.isBirthdayValid,
|
||||
controller: dateController,
|
||||
onChanged: (val) {
|
||||
final dateArray = val.split('.');
|
||||
if (dateArray.length != 3) return;
|
||||
final date = DateTime(int.parse(dateArray[2]), int.parse(dateArray[1]), int.parse(dateArray[0]));
|
||||
context.read<RegistrationCubitV2>().setBirthday(date);
|
||||
},
|
||||
),
|
||||
if (!state.isBirthdayValid) ...[const SizedBox(height: 4), ValidationErrorWidget(error: s.date_of_birth_error)],
|
||||
if (!state.isBirthdayValid) ...[
|
||||
const SizedBox(height: 4),
|
||||
ValidationErrorWidget(error: state.dateOfBirthDisplayError.isEmpty ? s.date_of_birth_error : state.dateOfBirthDisplayError),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -31,13 +31,13 @@ class _PasswordFieldState extends State<PasswordField> {
|
||||
width: double.infinity,
|
||||
child: Row(
|
||||
children: [
|
||||
Text('qweqweqwe', style: TextStyles.textMMediumAuto.copyWith(color: appTheme.black)),
|
||||
Text(state.password, style: TextStyles.textMMediumAuto.copyWith(color: appTheme.black)),
|
||||
const Spacer(),
|
||||
GestureDetector(
|
||||
onTap: copied
|
||||
? null
|
||||
: () async {
|
||||
Clipboard.setData(const ClipboardData(text: 'qweqwe'));
|
||||
Clipboard.setData(ClipboardData(text: state.password));
|
||||
setState(() {
|
||||
copied = true;
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@ class PhisicalActivity extends StatefulWidget {
|
||||
|
||||
class _PhisicalActivityState extends State<PhisicalActivity> {
|
||||
final List<String> activityDropDownTitles = [];
|
||||
|
||||
final List<double> activityDropDownValues = [1.2, 1.375, 1.55, 1.7, 1.9];
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
@@ -31,22 +31,22 @@ class _PhisicalActivityState extends State<PhisicalActivity> {
|
||||
}
|
||||
}
|
||||
|
||||
String _getTitleFromValue(double value) {
|
||||
switch (value) {
|
||||
case 1.2:
|
||||
return activityDropDownTitles[0];
|
||||
case 1.375:
|
||||
return activityDropDownTitles[1];
|
||||
case 1.55:
|
||||
return activityDropDownTitles[2];
|
||||
case 1.7:
|
||||
return activityDropDownTitles[3];
|
||||
case 1.9:
|
||||
return activityDropDownTitles[4];
|
||||
default:
|
||||
return activityDropDownTitles[5];
|
||||
}
|
||||
}
|
||||
// String _getTitleFromValue(double value) {
|
||||
// switch (value) {
|
||||
// case 1.2:
|
||||
// return activityDropDownTitles[0];
|
||||
// case 1.375:
|
||||
// return activityDropDownTitles[1];
|
||||
// case 1.55:
|
||||
// return activityDropDownTitles[2];
|
||||
// case 1.7:
|
||||
// return activityDropDownTitles[3];
|
||||
// case 1.9:
|
||||
// return activityDropDownTitles[4];
|
||||
// default:
|
||||
// return activityDropDownTitles[5];
|
||||
// }
|
||||
// }
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -55,26 +55,26 @@ class _PhisicalActivityState extends State<PhisicalActivity> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
CustomDropDownButton(
|
||||
// hasError: state.dietDurationError != null,
|
||||
CustomDropDownButton<double>(
|
||||
isExpanded: true,
|
||||
onChanged: (value) {
|
||||
if (value != null) {}
|
||||
if (value != null) {
|
||||
context.read<RegistrationCubitV2>().setActivityCoefficient(value);
|
||||
}
|
||||
},
|
||||
items: activityDropDownTitles
|
||||
.mapIndexed(
|
||||
(index, value) => DropdownMenuItem(
|
||||
value: activityDropDownTitles[index],
|
||||
(index, value) => DropdownMenuItem<double>(
|
||||
value: activityDropDownValues[index],
|
||||
child: Text(activityDropDownTitles[index], style: TextStyles.textMMedium.copyWith(color: appTheme.black)),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
value: state.activityCoefficient == 0 ? null : _getTitleFromValue(state.activityCoefficient),
|
||||
value: state.activityCoefficient == 0 ? null : state.activityCoefficient,
|
||||
selectedItemBuilder: (context) {
|
||||
return activityDropDownTitles.mapIndexed((index, value) => Text(value, overflow: TextOverflow.clip, maxLines: 1)).toList();
|
||||
return activityDropDownTitles.mapIndexed((index, value) => Text(activityDropDownTitles[index], overflow: TextOverflow.clip, maxLines: 1)).toList();
|
||||
},
|
||||
),
|
||||
// if (state.dietDurationError != null) ...[const SizedBox(height: 4), ValidationErrorWidget(error: state.dietDurationError ?? '')],
|
||||
],
|
||||
);
|
||||
},
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
||||
import 'package:eatvio_app/core/widgets/loader.dart';
|
||||
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart';
|
||||
import 'package:eatvio_app/features/registration_v2/cubit/registration_cubit.dart';
|
||||
import 'package:eatvio_app/features/registration_v2/cubit/registration_state.dart';
|
||||
@@ -17,8 +18,25 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class SecondStepContent extends StatelessWidget {
|
||||
class SecondStepContent extends StatefulWidget {
|
||||
const SecondStepContent({super.key});
|
||||
|
||||
@override
|
||||
State<SecondStepContent> createState() => _SecondStepContentState();
|
||||
}
|
||||
|
||||
class _SecondStepContentState extends State<SecondStepContent> {
|
||||
bool isLoading = false;
|
||||
final weightController = TextEditingController();
|
||||
final heightController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
heightController.text = context.read<RegistrationCubitV2>().state.height.toString();
|
||||
weightController.text = context.read<RegistrationCubitV2>().state.weight.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
@@ -39,7 +57,15 @@ class SecondStepContent extends StatelessWidget {
|
||||
children: [
|
||||
Text(s.height, style: TextStyles.textSMedium.copyWith(color: appTheme.black)),
|
||||
const SizedBox(height: 4),
|
||||
CustomTextFormField(hintText: s.type_height, hasError: !state.isHeightValid),
|
||||
CustomTextFormField(
|
||||
hintText: s.type_height,
|
||||
hasError: !state.isHeightValid,
|
||||
controller: heightController,
|
||||
textInputType: const TextInputType.numberWithOptions(),
|
||||
onChanged: (val) {
|
||||
context.read<RegistrationCubitV2>().setHeight(int.parse(val));
|
||||
},
|
||||
),
|
||||
if (!state.isHeightValid) ValidationErrorWidget(error: s.height_error),
|
||||
],
|
||||
),
|
||||
@@ -51,7 +77,15 @@ class SecondStepContent extends StatelessWidget {
|
||||
children: [
|
||||
Text(s.weight, style: TextStyles.textSMedium.copyWith(color: appTheme.black)),
|
||||
const SizedBox(height: 4),
|
||||
CustomTextFormField(hintText: s.type_weight, hasError: !state.isWeightValid),
|
||||
CustomTextFormField(
|
||||
hintText: s.type_weight,
|
||||
hasError: !state.isWeightValid,
|
||||
controller: weightController,
|
||||
textInputType: const TextInputType.numberWithOptions(),
|
||||
onChanged: (val) {
|
||||
context.read<RegistrationCubitV2>().setWeight(int.parse(val));
|
||||
},
|
||||
),
|
||||
if (!state.isWeightValid) ValidationErrorWidget(error: s.weight_error),
|
||||
],
|
||||
),
|
||||
@@ -78,17 +112,32 @@ class SecondStepContent extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: CustomOutlinedButton(
|
||||
onPressed: () {
|
||||
showRegistrationBottomSheet(context, context.read<RegistrationCubitV2>(), false, () async {});
|
||||
},
|
||||
text: s.register,
|
||||
height: 52,
|
||||
buttonTextStyle: TextStyles.textSSemibold.copyWith(color: appTheme.whiteA700),
|
||||
buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)),
|
||||
),
|
||||
),
|
||||
isLoading
|
||||
? const Expanded(child: Center(child: Loader()))
|
||||
: Expanded(
|
||||
child: CustomOutlinedButton(
|
||||
onPressed: () async {
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
final cubit = context.read<RegistrationCubitV2>();
|
||||
final (commonResult, hasValidationError) = await cubit.register();
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
if (context.mounted && !hasValidationError) {
|
||||
showRegistrationBottomSheet(context, cubit, commonResult);
|
||||
}
|
||||
},
|
||||
text: s.register,
|
||||
height: 52,
|
||||
buttonTextStyle: TextStyles.textSSemibold.copyWith(color: appTheme.whiteA700),
|
||||
buttonStyle: ButtonStyle(
|
||||
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:eatvio_app/core/app_router.dart';
|
||||
import 'package:eatvio_app/core/routing/route_constants.dart';
|
||||
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
|
||||
@@ -6,8 +8,9 @@ import 'package:eatvio_app/features/registration_v2/presentation/widgets/passwor
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
void showRegistrationBottomSheet(BuildContext context, RegistrationCubitV2 cubit, bool isSuccess, Future<void> Function() tryAgain) {
|
||||
void showRegistrationBottomSheet(BuildContext context, RegistrationCubitV2 cubit, bool isSuccess) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
@@ -30,6 +33,7 @@ class RegistrationBottomSheet extends StatefulWidget {
|
||||
|
||||
class _RegistrationBottomSheetState extends State<RegistrationBottomSheet> {
|
||||
late bool isSuccess;
|
||||
bool isLoading = false;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -71,7 +75,9 @@ class _RegistrationBottomSheetState extends State<RegistrationBottomSheet> {
|
||||
height: 52,
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
||||
buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)),
|
||||
onPressed: () async {},
|
||||
onPressed: () async {
|
||||
AppRouter.navigatorKey.currentContext?.go(RouteConstants.feedScreen);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
//button
|
||||
@@ -92,13 +98,6 @@ class _RegistrationBottomSheetState extends State<RegistrationBottomSheet> {
|
||||
padding: const EdgeInsets.only(bottom: 16.0),
|
||||
child: Text(s.error_desc, style: TextStyles.textMMediumAuto.copyWith(color: appTheme.darkGrey)),
|
||||
),
|
||||
CustomOutlinedButton(
|
||||
text: s.try_again,
|
||||
height: 52,
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
||||
buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)),
|
||||
onPressed: () async {},
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user