Files
eatvio_app/lib/features/registration/presentation/pages/weight_screen.dart
2024-11-20 14:30:48 +03:00

59 lines
2.0 KiB
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:eatvio_app/generated/l10n.dart';
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class WeightScreen extends StatefulWidget {
final UserRegistrationSheet sheet;
const WeightScreen({super.key, required this.sheet});
@override
State<WeightScreen> createState() => _WeightScreenState();
}
class _WeightScreenState extends State<WeightScreen> {
final weightController = TextEditingController();
final weightFocus = FocusNode();
@override
void initState() {
super.initState();
if (widget.sheet.weight != 0) weightController.text = widget.sheet.weight.toString();
weightFocus.requestFocus();
}
@override
Widget build(BuildContext context) {
final s = S.of(context);
return SingleChildScrollView(
padding: EdgeInsets.only(bottom: 80, left: 16, right: 16, top: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(s.your_weight),
SizedBox(height: 4),
CustomTextFormField(
autofocus: true,
hintText: 'кг',
focusNode: weightFocus,
textInputAction: TextInputAction.done,
controller: weightController,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly,
],
onChanged: (newValue) {
final registrationCubit = context.read<RegistrationCubit>();
registrationCubit.updateSheet(registrationCubit.state.sheet.copyWith(weight: int.parse(newValue)));
},
),
],
),
);
}
}