forked from eatvio/eatvio_app
67 lines
2.1 KiB
Dart
67 lines
2.1 KiB
Dart
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
|
import 'package:eatvio_app/features/registration/models/user_registration_model.dart';
|
|
import 'package:eatvio_app/features/registration/presentation/bloc/registration_cubit/registration_cubit.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:mask_text_input_formatter/mask_text_input_formatter.dart';
|
|
|
|
class PhoneScreen extends StatefulWidget {
|
|
final UserRegistrationSheet sheet;
|
|
|
|
const PhoneScreen({
|
|
super.key,
|
|
required this.sheet,
|
|
});
|
|
|
|
@override
|
|
State<PhoneScreen> createState() => _PhoneScreenState();
|
|
}
|
|
|
|
class _PhoneScreenState extends State<PhoneScreen> {
|
|
final phoneController = TextEditingController();
|
|
final phoneFocus = FocusNode();
|
|
|
|
final maskFormatter = MaskTextInputFormatter(
|
|
mask: '+7 (###) ### ## ##',
|
|
filter: {"#": RegExp(r'[0-9]')},
|
|
);
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
if (widget.sheet.phone.isNotEmpty) phoneController.text = widget.sheet.phone;
|
|
phoneFocus.requestFocus();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SingleChildScrollView(
|
|
padding: const EdgeInsets.only(bottom: 80, left: 16, right: 16, top: 16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text('Номер телефона'),
|
|
const SizedBox(height: 4),
|
|
CustomTextFormField(
|
|
textInputAction: TextInputAction.done,
|
|
autofocus: true,
|
|
focusNode: phoneFocus,
|
|
hintText: '+7 (999) 999 99 99',
|
|
controller: phoneController,
|
|
keyboardType: TextInputType.number,
|
|
inputFormatters: [maskFormatter],
|
|
onChanged: (newValue) {
|
|
final registrationCubit = context.read<RegistrationCubit>();
|
|
registrationCubit.updateSheet(
|
|
registrationCubit.state.sheet.copyWith(
|
|
phone: newValue,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|