auth phone and re auth phone
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
import 'package:prosappco/blocs/auth_bloc/auth_bloc.dart';
|
||||
import 'package:prosappco/components/general_primary_button.dart';
|
||||
|
||||
class ProfileUpdatePasswordScreen extends StatefulWidget {
|
||||
final String email;
|
||||
|
||||
const ProfileUpdatePasswordScreen({super.key, required this.email});
|
||||
|
||||
@override
|
||||
State<ProfileUpdatePasswordScreen> createState() =>
|
||||
_ProfileUpdatePasswordScreenState();
|
||||
}
|
||||
|
||||
class _ProfileUpdatePasswordScreenState
|
||||
extends State<ProfileUpdatePasswordScreen> {
|
||||
final TextEditingController _actualPasswordController =
|
||||
TextEditingController();
|
||||
final TextEditingController _passwordController = TextEditingController();
|
||||
final TextEditingController _confirmPasswordController =
|
||||
TextEditingController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final authBloc = Injector.appInstance.get<AuthBloc>();
|
||||
return BlocProvider<AuthBloc>(
|
||||
create: (context) => authBloc,
|
||||
child: BlocConsumer<AuthBloc, AuthState>(
|
||||
listener: (context, state) {
|
||||
if (state is AuthStateSuccess) {
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('Se actualizo la contraseña.🥳'),
|
||||
));
|
||||
} else if (state is AuthStateFailure) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(state.message ?? 'Error inesperado. 🥸'),
|
||||
));
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Actualizar contraseña'),
|
||||
),
|
||||
body: Center(
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 40, vertical: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _actualPasswordController,
|
||||
obscureText: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Contraseña actual',
|
||||
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: 'Nueva 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: _confirmPasswordController,
|
||||
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 (_actualPasswordController.text.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_passwordController.text.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_confirmPasswordController.text.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_passwordController.text !=
|
||||
_confirmPasswordController.text) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_actualPasswordController.text ==
|
||||
_passwordController.text &&
|
||||
_actualPasswordController.text ==
|
||||
_confirmPasswordController.text) {
|
||||
return;
|
||||
}
|
||||
|
||||
authBloc.add(AuthEventUpdatePassword(
|
||||
email: widget.email,
|
||||
password: _passwordController.text,
|
||||
actualPassword: _actualPasswordController.text));
|
||||
},
|
||||
label: 'Actualizar contraseña',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user