feature(registration): refactor i5

This commit is contained in:
mso7nueh
2024-07-15 12:45:52 +03:00
parent 8cf2388b18
commit ee37f02d78
15 changed files with 470 additions and 718 deletions

View File

@@ -1,14 +1,8 @@
import 'package:go_router/go_router.dart';
import 'bloc/additional_information_bloc.dart';
import 'package:eatvio_app/features/registration/presentation/bloc/registration_cubit/registration_cubit.dart';
import 'package:eatvio_app/core/app_export.dart';
import 'package:eatvio_app/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:hive/hive.dart';
import 'package:http/http.dart' as http;
class AdditionalInformationScreen extends StatefulWidget {
final UserRegistrationSheet sheet;
@@ -20,6 +14,14 @@ class AdditionalInformationScreen extends StatefulWidget {
}
class _AdditionalInformationScreenState extends State<AdditionalInformationScreen> {
final editTextController = TextEditingController();
@override
void initState() {
super.initState();
editTextController.text = widget.sheet.additionalInfo;
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
@@ -29,117 +31,31 @@ class _AdditionalInformationScreenState extends State<AdditionalInformationScree
padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v),
child: Column(
children: [
_buildTextFormField(context),
// BlocBuilder<AdditionalInformationBloc, AdditionalInformationState>(
// builder: (context, state) {
// return NextStepButton(
// text: "finish".tr.toUpperCase(),
// margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v),
// buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
// onPressed: onTapFinish(state, context),
// );
// },
// ),
Container(
width: 294.h,
margin: EdgeInsets.only(left: 24.h, right: 23.h),
child: Text(
"enter_additional_information".tr,
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
style: CustomTextStyles.titleMediumSegoeUI,
),
),
SizedBox(height: 10.v),
CustomTextFormField(
controller: editTextController,
hintText: "У меня крепкое здоровье, но последнее время часто утомляюсь, однако, это мне не мешает радоваться жизни",
textInputAction: TextInputAction.done,
maxLines: 8,
onChanged: (newValue) {
final registrationCubit = context.read<RegistrationCubit>();
registrationCubit.updateSheet(registrationCubit.state.sheet.copyWith(additionalInfo: newValue));
},
),
],
),
),
);
}
onTapFinish(AdditionalInformationState state, BuildContext context) {
return () async {
UserRegistrationSheet sheet = state.additionalInformationModelObj!.userRegistrationSheet;
// sheet.additionalInfo = state.editTextController!.text;
final response = await http.post(
Uri.parse(dotenv.env['SERVER_ROOT']! + '/register'),
headers: {'Content-Type': 'application/json', 'Accept': 'application/json'},
body: jsonEncode(sheet.toJson()),
encoding: utf8,
);
var res = await jsonDecode(response.body);
if (response.statusCode == 200) {
final box = await Hive.openBox('token');
final token = res['token'];
box.put('token', token);
GoRouter.of(context).goNamed('myProfileScreen');
} else {
showErrorMessage(context, res['message']);
}
};
}
onTapBack(BuildContext context) {
return () {
onTapArrowLeft(context);
};
}
/// Section Widget
_buildTextFormField(BuildContext context) {
return SizedBox(
width: 343.h,
child: Stack(
alignment: Alignment.center,
children: [
Align(
alignment: Alignment.center,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 294.h,
margin: EdgeInsets.only(left: 24.h, right: 23.h),
child: Text(
"enter_additional_information".tr,
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
style: CustomTextStyles.titleMediumSegoeUI,
),
),
SizedBox(height: 10.v),
BlocSelector<AdditionalInformationBloc, AdditionalInformationState, TextEditingController?>(
selector: (state) => state.editTextController,
builder: (context, editTextController) {
return CustomTextFormField(
controller: editTextController,
hintText: "У меня крепкое здоровье, но последнее время часто утомляюсь, однако, это мне не мешает радоваться жизни",
textInputAction: TextInputAction.done,
maxLines: 8,
);
},
),
],
),
),
],
),
);
}
/// Navigates to the previous screen.
onTapArrowLeft(BuildContext context) {
GoRouter.of(context).pop();
}
/// Displays an alert dialog when the action is triggered.
/// The dialog box contains a title and a message with the `Теперь вы можете пользоваться полным функционалом приложения`
showErrorMessage(BuildContext context, String text) {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: const Text('Ошибка'),
content: Text(text),
actions: [TextButton(onPressed: onTapOk(context), child: const Text('Ok'))],
),
);
}
onTapOk(BuildContext context) {
return () {
Navigator.pop(context);
};
}
}