services
This commit is contained in:
@@ -6,6 +6,8 @@ import 'package:prosappco/blocs/auth_bloc/auth_bloc.dart';
|
||||
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
|
||||
import 'package:prosappco/components/general_primary_button.dart';
|
||||
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
class ProfileRegisterEmailScreen extends StatefulWidget {
|
||||
const ProfileRegisterEmailScreen({super.key});
|
||||
|
||||
@@ -14,13 +16,38 @@ class ProfileRegisterEmailScreen extends StatefulWidget {
|
||||
_ProfileRegisterEmailScreenState();
|
||||
}
|
||||
|
||||
class _ProfileRegisterEmailScreenState extends State<ProfileRegisterEmailScreen> {
|
||||
class _ProfileRegisterEmailScreenState
|
||||
extends State<ProfileRegisterEmailScreen> {
|
||||
final TextEditingController _emailController = TextEditingController();
|
||||
final TextEditingController _passwordController = TextEditingController();
|
||||
final TextEditingController _confirmPasswordController =
|
||||
TextEditingController();
|
||||
|
||||
late final AuthBloc authBloc;
|
||||
late String verificationCode;
|
||||
|
||||
String? validateEmail(String? email) {
|
||||
RegExp emailRegex = RegExp(r'^[\w\.-]+@[\w-]+\.\w{2,3}(\.\w{2,3})?$');
|
||||
final isEmailValid = emailRegex.hasMatch(email ?? '');
|
||||
|
||||
if (isEmailValid) {
|
||||
return null;
|
||||
} else {
|
||||
return 'Ingresa un correo electronico valido';
|
||||
}
|
||||
}
|
||||
|
||||
String? validatePassword(String? password) {
|
||||
RegExp passwordRegex = RegExp(r'^(?=.*?[0-9])');
|
||||
final isPasswordValid = passwordRegex.hasMatch(password ?? '');
|
||||
|
||||
if (isPasswordValid) {
|
||||
return null;
|
||||
} else {
|
||||
return 'La contraseña debe tener al menos un número';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -31,6 +58,7 @@ class _ProfileRegisterEmailScreenState extends State<ProfileRegisterEmailScreen>
|
||||
void dispose() {
|
||||
_emailController.dispose();
|
||||
_passwordController.dispose();
|
||||
_confirmPasswordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -46,7 +74,6 @@ class _ProfileRegisterEmailScreenState extends State<ProfileRegisterEmailScreen>
|
||||
child: BlocConsumer<AuthBloc, AuthState>(
|
||||
listener: (context, state) {
|
||||
if (state is AuthStateSuccess) {
|
||||
// here update email and password autentication
|
||||
authBloc.add(
|
||||
AuthEventAddEmailAndPassword(
|
||||
email: _emailController.text,
|
||||
@@ -82,7 +109,6 @@ class _ProfileRegisterEmailScreenState extends State<ProfileRegisterEmailScreen>
|
||||
numberOfFields: 6,
|
||||
fieldWidth: 35,
|
||||
borderColor: const Color(0xFF512DA8),
|
||||
// showFieldAsBox: true,
|
||||
onCodeChanged: (String code) {
|
||||
verificationCode = code;
|
||||
},
|
||||
@@ -110,7 +136,6 @@ class _ProfileRegisterEmailScreenState extends State<ProfileRegisterEmailScreen>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// _showLoginModal(context);
|
||||
return BlocProvider<AuthBloc>(
|
||||
create: (context) => authBloc,
|
||||
child: BlocListener<AuthBloc, AuthState>(
|
||||
@@ -126,9 +151,7 @@ class _ProfileRegisterEmailScreenState extends State<ProfileRegisterEmailScreen>
|
||||
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
if (state is AuthStateRequiresRecentLogin) {
|
||||
// _showLoginModal(context, state);
|
||||
}
|
||||
if (state is AuthStateRequiresRecentLogin) {}
|
||||
},
|
||||
child: BlocBuilder<MyUserBloc, MyUserState>(
|
||||
builder: (context, state) {
|
||||
@@ -139,112 +162,113 @@ class _ProfileRegisterEmailScreenState extends State<ProfileRegisterEmailScreen>
|
||||
appBar: AppBar(
|
||||
title: const Text('Agregar correo'),
|
||||
),
|
||||
body: Center(
|
||||
// Centro del contenido
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 40, vertical: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _emailController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Email',
|
||||
prefixIcon: Icon(Icons.email_rounded),
|
||||
hintText: 'Email',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10.0),
|
||||
)),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.red),
|
||||
),
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(color: Colors.red, width: 2.0),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 40, vertical: 10),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _emailController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Email',
|
||||
prefixIcon: const Icon(Icons.email_rounded),
|
||||
hintText: 'Email',
|
||||
border: inputBorder(),
|
||||
errorBorder: inputBorderError(),
|
||||
focusedErrorBorder: inputBorderFocus(),
|
||||
),
|
||||
validator: validateEmail,
|
||||
autovalidateMode:
|
||||
AutovalidateMode.onUserInteraction,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Contraseña',
|
||||
prefixIcon: const Icon(Icons.lock_rounded),
|
||||
hintText: 'Contraseña',
|
||||
border: inputBorder(),
|
||||
errorBorder: inputBorderError(),
|
||||
focusedErrorBorder: inputBorderFocus(),
|
||||
),
|
||||
validator: validatePassword,
|
||||
autovalidateMode:
|
||||
AutovalidateMode.onUserInteraction,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextFormField(
|
||||
controller: _confirmPasswordController,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Confirmar contraseña',
|
||||
prefixIcon: const Icon(Icons.lock_rounded),
|
||||
hintText: 'Contraseña',
|
||||
border: inputBorder(),
|
||||
errorBorder: inputBorderError(),
|
||||
focusedErrorBorder: inputBorderFocus(),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value != _passwordController.text) {
|
||||
return 'Las contraseñas no coinciden';
|
||||
}
|
||||
if (value!.isEmpty) {
|
||||
return 'La contraseña es obligatoria';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
autovalidateMode:
|
||||
AutovalidateMode.onUserInteraction,
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
],
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Por favor, ingrese su contraseña';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
obscureText: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Contraseña',
|
||||
prefixIcon: Icon(Icons.lock_rounded),
|
||||
hintText: 'Contraseña',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10.0),
|
||||
)),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.red),
|
||||
),
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(color: Colors.red, width: 2.0),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Por favor, ingrese su contraseña';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
obscureText: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Confirmar contraseña',
|
||||
prefixIcon: Icon(Icons.lock_rounded),
|
||||
hintText: 'Contraseña',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10.0),
|
||||
)),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.red),
|
||||
),
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(color: Colors.red, width: 2.0),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Por favor, ingrese su contraseña';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
GeneralPrimaryButton(
|
||||
onPressed: () {
|
||||
if (_emailController.text.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_passwordController.text.isEmpty) {
|
||||
return;
|
||||
}
|
||||
_showLoginModal(context, state);
|
||||
},
|
||||
label: 'Guardar',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(
|
||||
height: 1,
|
||||
thickness: 0.5,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10,
|
||||
horizontal: 15,
|
||||
),
|
||||
child: FilledButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_showLoginModal(context, state);
|
||||
}
|
||||
},
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor:
|
||||
Theme.of(context).colorScheme.primary,
|
||||
padding: const EdgeInsets.symmetric(vertical: 15),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
width: double.infinity,
|
||||
child: const Text(
|
||||
'Guardar',
|
||||
style: TextStyle(color: Colors.white, fontSize: 18),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
@@ -255,4 +279,27 @@ class _ProfileRegisterEmailScreenState extends State<ProfileRegisterEmailScreen>
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
OutlineInputBorder inputBorderFocus() {
|
||||
return OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Colors.red,
|
||||
width: 2.0,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
OutlineInputBorder inputBorderError() {
|
||||
return OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.red),
|
||||
);
|
||||
}
|
||||
|
||||
OutlineInputBorder inputBorder() {
|
||||
return OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10.0),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user