Registration pipeline chenged - fill profile step added. Order payment fixed
This commit is contained in:
@@ -9,15 +9,22 @@ import '../../domain/entities/user_profile.dart';
|
||||
import '../components/custom_app_bar.dart';
|
||||
import '../components/gradient_button.dart';
|
||||
import '../event/edit_profile_event.dart';
|
||||
import '../state/edit_profile_state.dart';
|
||||
import '../event/profile_event.dart';
|
||||
import '../event/spalsh_event.dart';
|
||||
import '../state/edit_profile_state.dart';
|
||||
import '../viewmodel/edit_profile_bloc.dart';
|
||||
import '../viewmodel/profile_bloc.dart';
|
||||
import '../viewmodel/splash_bloc.dart';
|
||||
|
||||
class EditProfileScreen extends StatefulWidget {
|
||||
final UserProfile profile;
|
||||
final bool isRegistration;
|
||||
|
||||
const EditProfileScreen({super.key, required this.profile});
|
||||
const EditProfileScreen({
|
||||
super.key,
|
||||
required this.profile,
|
||||
this.isRegistration = false,
|
||||
});
|
||||
|
||||
@override
|
||||
State<EditProfileScreen> createState() => _EditProfileScreenState();
|
||||
@@ -52,6 +59,36 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
||||
}
|
||||
}
|
||||
birthDateController = TextEditingController(text: initialDateText);
|
||||
|
||||
nameController.addListener(_onFieldChanged);
|
||||
birthDateController.addListener(_onFieldChanged);
|
||||
phoneController.addListener(_onFieldChanged);
|
||||
emailController.addListener(_onFieldChanged);
|
||||
}
|
||||
|
||||
void _onFieldChanged() {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
bool get _isFormValid {
|
||||
return nameController.text.trim().isNotEmpty &&
|
||||
birthDateController.text.trim().isNotEmpty &&
|
||||
phoneController.text.trim().isNotEmpty &&
|
||||
emailController.text.trim().isNotEmpty;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
nameController.removeListener(_onFieldChanged);
|
||||
birthDateController.removeListener(_onFieldChanged);
|
||||
phoneController.removeListener(_onFieldChanged);
|
||||
emailController.removeListener(_onFieldChanged);
|
||||
|
||||
nameController.dispose();
|
||||
birthDateController.dispose();
|
||||
phoneController.dispose();
|
||||
emailController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit(BuildContext context) {
|
||||
@@ -61,14 +98,13 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
||||
final String birthDateForApi = _selectedBirthDate?.toIso8601String() ?? '';
|
||||
|
||||
final updatedProfile = profileFromState.copyWith(
|
||||
name: nameController.text,
|
||||
name: nameController.text.trim(),
|
||||
birthDate: birthDateForApi.isNotEmpty ? "${birthDateForApi}Z" : '',
|
||||
email: emailController.text,
|
||||
email: emailController.text.trim(),
|
||||
);
|
||||
|
||||
context.read<EditProfileBloc>().add(EditProfileSubmitted(updatedProfile));
|
||||
context.read<ProfileBloc>().add(ProfileUpdated());
|
||||
|
||||
}
|
||||
|
||||
Future<void> _selectDate(BuildContext context) async {
|
||||
@@ -90,6 +126,8 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool isButtonEnabled = widget.isRegistration ? _isFormValid : true;
|
||||
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(gradient: AppColors.phoneScreenBg),
|
||||
@@ -104,15 +142,21 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
||||
phoneController.text = profile.phone;
|
||||
emailController.text = profile.email;
|
||||
birthDateController.text = profile.birthDate;
|
||||
|
||||
}
|
||||
|
||||
if (state.isSuccess) {
|
||||
getIt<ProfileBloc>().add(ProfileUpdated());
|
||||
context.pop();
|
||||
if (widget.isRegistration) {
|
||||
context.read<SplashBloc>().add(PinVerificationSuccess());
|
||||
context.go('/home');
|
||||
} else {
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
if (state.error != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(state.error!)));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.error!)),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
@@ -125,7 +169,10 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
||||
return Column(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
CustomAppBar(title: 'Личные данные'),
|
||||
CustomAppBar(
|
||||
title: widget.isRegistration ? 'Заполните профиль' : 'Личные данные',
|
||||
showBackButton: !widget.isRegistration,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
_Field(
|
||||
'Имя',
|
||||
@@ -137,9 +184,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
||||
birthDateController,
|
||||
iconPath: 'assets/icons/edit.png',
|
||||
readOnly: true,
|
||||
onTap: () => _selectDate(
|
||||
context,
|
||||
),
|
||||
onTap: () => _selectDate(context),
|
||||
),
|
||||
_Field(
|
||||
'Телефон',
|
||||
@@ -156,13 +201,13 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
||||
state.isSaving
|
||||
? const CircularProgressIndicator(color: Colors.white)
|
||||
: GradientButton(
|
||||
text: 'Сохранить изменения',
|
||||
onTap: () => _submit(context),
|
||||
width: double.infinity,
|
||||
height: 56,
|
||||
fontSize: 16,
|
||||
showArrows: true,
|
||||
),
|
||||
text: widget.isRegistration ? 'Продолжить' : 'Сохранить изменения',
|
||||
onTap: isButtonEnabled ? () => _submit(context) : null,
|
||||
width: double.infinity,
|
||||
height: 56,
|
||||
fontSize: 16,
|
||||
showArrows: true,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
);
|
||||
@@ -173,7 +218,6 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class _Field extends StatelessWidget {
|
||||
|
||||
Reference in New Issue
Block a user