Files
eatvio_app/lib/presentation/registration/name_screen/name_screen.dart
2024-07-11 17:39:36 +03:00

133 lines
4.3 KiB
Dart

import 'package:go_router/go_router.dart';
import 'bloc/name_bloc.dart';
import 'models/name_model.dart';
import 'package:eatvio_app/core/app_export.dart';
import 'package:eatvio_app/widgets/custom_text_form_field.dart';
import 'package:flutter/material.dart';
class NameScreen extends StatelessWidget {
const NameScreen({Key? key}) : super(key: key);
static Widget builder(BuildContext context, sheet) {
return BlocProvider<NameBloc>(
create: (context) => NameBloc(
NameState(
nameModelObj: NameModel(userRegistrationSheet: sheet),
),
)..add(NameInitialEvent()),
child: NameScreen(),
);
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
padding: EdgeInsets.only(bottom: 80),
child: Container(
width: double.maxFinite,
padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 9.v),
child: Column(
children: [
Text("what_is_your_name".tr, style: theme.textTheme.headlineSmall),
SizedBox(height: 93.v),
Text("first_name".tr, style: theme.textTheme.bodyLarge),
SizedBox(height: 3.v),
BlocSelector<NameBloc, NameState, TextEditingController?>(
selector: (state) => state.firstNameController,
builder: (context, firstNameController) {
return CustomTextFormField(controller: firstNameController, textInputAction: TextInputAction.done);
},
),
SizedBox(height: 19.v),
Text("last_name".tr, style: theme.textTheme.bodyLarge),
SizedBox(height: 5.v),
BlocSelector<NameBloc, NameState, TextEditingController?>(
selector: (state) => state.lastNameController,
builder: (context, lastNameController) {
return CustomTextFormField(
controller: lastNameController,
);
},
),
// BlocBuilder<NameBloc, NameState>(
// builder: (context, state) {
// return NextStepButton(
// text: "continue".tr.toUpperCase(),
// margin: EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v),
// buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
// onPressed: () => _onTapNext(context, state), // Assign callback function here
// );
// },
// ),
],
),
),
);
}
/// Navigates to the previous screen.
onTapArrowLeft(BuildContext context) {
GoRouter.of(context).pop();
}
// _onTapNext(BuildContext context, NameState state) {
// if (state.firstNameController != null && state.lastNameController != null) {
// List<String> errors = validateFields(state.firstNameController!.text, state.lastNameController!.text);
//
// if (errors.isEmpty) {
// UserRegistrationSheet sheet = state.nameModelObj!.userRegistrationSheet;
// sheet.firstName = state.firstNameController!.text;
// sheet.lastName = state.lastNameController!.text;
// AppRouter.navigatorKey.currentContext?.goNamed('genderScreen', extra: sheet);
// } else {
// String errorMessage = '';
//
// for (var error in errors) {
// errorMessage += error + '\n\n';
// }
//
// showDialog(
// context: context,
// builder: (context) => AlertDialog(
// title: Text('Error'),
// content: Text(errorMessage),
// actions: [
// TextButton(
// onPressed: () => onTapOk(context),
// child: Text('OK'),
// ),
// ],
// ),
// );
// }
// }
// }
void onTapOk(BuildContext context) {
Navigator.pop(context);
}
List<String> validateFields(String firstName, String lastName) {
List<String> errors = [];
if (firstName.isEmpty) {
errors.add('First name cannot be empty');
}
if (firstName.length < 1) {
errors.add('First name is too short');
}
if (lastName.isEmpty) {
errors.add('Last name cannot be empty');
}
if (lastName.length < 1) {
errors.add('Last name is too short');
}
return errors;
}
}