This commit is contained in:
Felipe
2024-02-27 17:32:16 -05:00
parent 906ebb4330
commit a71fc9efb6
17 changed files with 1189 additions and 526 deletions
+11
View File
@@ -13,6 +13,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
super(AuthStateInitial()) { super(AuthStateInitial()) {
on<AuthEventLoginOAuth>(_onAuthEventLoginOAuth); on<AuthEventLoginOAuth>(_onAuthEventLoginOAuth);
on<AuthEventVerifyOAuth>(_onAuthEventVerifyOAuth); on<AuthEventVerifyOAuth>(_onAuthEventVerifyOAuth);
on<AuthEventAddEmailAndPassword>(_onAuthEventAddEmailAndPassword);
} }
void _onAuthEventLoginOAuth( void _onAuthEventLoginOAuth(
@@ -46,4 +47,14 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
emit(const AuthStateFailure()); emit(const AuthStateFailure());
} }
} }
void _onAuthEventAddEmailAndPassword(
AuthEventAddEmailAndPassword event, Emitter<AuthState> emit) async {
emit(AuthStateProcess());
try {
await _userRepository.addEmailAndPassword(event.email, event.password);
} catch (e) {
emit(const AuthStateFailure());
}
}
} }
+13
View File
@@ -18,3 +18,16 @@ class AuthEventVerifyOAuth extends AuthEvent {
const AuthEventVerifyOAuth({required this.code}); const AuthEventVerifyOAuth({required this.code});
} }
class AuthEventAddEmailAndPassword extends AuthEvent {
final String email;
final String password;
const AuthEventAddEmailAndPassword({
required this.email,
required this.password,
});
@override
List<Object> get props => [email, password];
}
+7 -14
View File
@@ -1,5 +1,6 @@
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:prosappco/blocs/auth_bloc/auth_bloc.dart';
import 'package:user_repository/user_repository.dart'; import 'package:user_repository/user_repository.dart';
part 'profile_event.dart'; part 'profile_event.dart';
@@ -7,25 +8,17 @@ part 'profile_state.dart';
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> { class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
final UserRepository _userRepository; final UserRepository _userRepository;
// final AuthBloc _authBloc; // lo nuevo
ProfileBloc({required UserRepository userRepository}) ProfileBloc({
: _userRepository = userRepository, required UserRepository userRepository,
// required AuthBloc authBloc
}) : _userRepository = userRepository,
// _authBloc = authBloc,
super(UpdateUserInfoInitial()) { super(UpdateUserInfoInitial()) {
// on<UploadPicture>(_onUploadPicture);
on<UpdateUserInfo>(_onUpdateUserInfo); on<UpdateUserInfo>(_onUpdateUserInfo);
} }
// void _onUploadPicture(UploadPicture event, Emitter<ProfileState> emit) async {
// emit(UploadPictureLoading());
// try {
// String userImage =
// await _userRepository.uploadPicture(event.file, event.userId);
// emit(UploadPictureSuccess(userImage));
// } catch (e) {
// emit(UploadPictureFailure());
// }
// }
void _onUpdateUserInfo( void _onUpdateUserInfo(
UpdateUserInfo event, Emitter<ProfileState> emit) async { UpdateUserInfo event, Emitter<ProfileState> emit) async {
emit(UpdateUserInfoLoading()); emit(UpdateUserInfoLoading());
+1 -1
View File
@@ -34,7 +34,7 @@ class _GenderDropdownState extends State<GenderDropdown> {
child: DropdownButtonHideUnderline( child: DropdownButtonHideUnderline(
child: DropdownButton<String>( child: DropdownButton<String>(
isExpanded: true, isExpanded: true,
value: controller.text, value: controller.text == '' ? null : controller.text,
hint: const Text( hint: const Text(
'Selecciona tu género', 'Selecciona tu género',
style: TextStyle(fontSize: 16.0), style: TextStyle(fontSize: 16.0),
+28
View File
@@ -0,0 +1,28 @@
import 'package:flutter/material.dart';
class GeneralCheckbox extends StatelessWidget {
final String text;
final bool initialValue;
final Function(bool) onChanged;
const GeneralCheckbox({
super.key,
required this.text,
required this.initialValue,
required this.onChanged,
});
@override
Widget build(BuildContext context) {
return CheckboxListTile(
title: Text(
text,
style: const TextStyle(fontSize: 15),
),
value: initialValue,
onChanged: (value) {
onChanged(value!);
},
);
}
}
+32 -2
View File
@@ -1,10 +1,40 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class GeneralPrimaryButton extends StatelessWidget { class GeneralPrimaryButton extends StatelessWidget {
const GeneralPrimaryButton({super.key}); final VoidCallback onPressed;
final String label;
final bool isEnabled;
const GeneralPrimaryButton({
super.key,
required this.onPressed,
required this.label,
this.isEnabled = true,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container(); return ElevatedButton(
onPressed: isEnabled ? onPressed : null,
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
elevation: 0,
minimumSize: Size(
MediaQuery.of(context).size.width * 0.5,
50,
),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(50)),
),
),
child: Text(
label,
style: TextStyle(
color: isEnabled ? Colors.white : Colors.black,
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
);
} }
} }
+116 -85
View File
@@ -24,6 +24,7 @@ class _SignInScreenState extends State<SignInScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final width = MediaQuery.of(context).size.width;
return BlocListener<SignInBloc, SignInState>( return BlocListener<SignInBloc, SignInState>(
listener: (context, state) { listener: (context, state) {
if (state is SignInSuccess) { if (state is SignInSuccess) {
@@ -41,103 +42,133 @@ class _SignInScreenState extends State<SignInScreen> {
}); });
} }
}, },
child: Form( child: Column(
key: _formKey, children: [
child: Column( SizedBox(
children: [ width: double.infinity,
const SizedBox(height: 20), child: Row(
SizedBox( children: [
width: MediaQuery.of(context).size.width * 0.9, IconButton(
child: MyTextField( onPressed: () {
controller: emailController, Navigator.pop(context);
hintText: 'Email', },
obscureText: false, icon: const Icon(
keyboardType: TextInputType.emailAddress, CupertinoIcons.arrow_left,
prefixIcon: Icon( size: 30,
CupertinoIcons.mail_solid, ),
color: Colors.grey[600], ),
), Text(
'Iniciar sesión',
style: TextStyle(
// fontSize: 30,
fontSize: width * 0.08,
fontWeight: FontWeight.bold,
),
),
],
),
),
Form(
key: _formKey,
child: Column(
children: [
const SizedBox(height: 20),
SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: MyTextField(
controller: emailController,
hintText: 'Email',
obscureText: false,
keyboardType: TextInputType.emailAddress,
prefixIcon: Icon(
CupertinoIcons.mail_solid,
color: Colors.grey[600],
),
errorMsg: _errorMsg,
validator: (val) {
if (val!.isEmpty) {
return 'Please fill in this field';
} else if (!emailRexExp.hasMatch(val)) {
return 'Please enter a valid email';
}
return null;
}),
),
const SizedBox(height: 10),
SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: MyTextField(
controller: passwordController,
hintText: 'Password',
obscureText: obscurePassword,
keyboardType: TextInputType.visiblePassword,
prefixIcon:
Icon(CupertinoIcons.lock_fill, color: Colors.grey[600]),
errorMsg: _errorMsg, errorMsg: _errorMsg,
validator: (val) { validator: (val) {
if (val!.isEmpty) { if (val!.isEmpty) {
return 'Please fill in this field'; return 'Please fill in this field';
} else if (!emailRexExp.hasMatch(val)) { } else if (!passwordRexExp.hasMatch(val)) {
return 'Please enter a valid email'; return 'Please enter a valid password';
} }
return null; return null;
}),
),
const SizedBox(height: 10),
SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: MyTextField(
controller: passwordController,
hintText: 'Password',
obscureText: obscurePassword,
keyboardType: TextInputType.visiblePassword,
prefixIcon:
Icon(CupertinoIcons.lock_fill, color: Colors.grey[600]),
errorMsg: _errorMsg,
validator: (val) {
if (val!.isEmpty) {
return 'Please fill in this field';
} else if (!passwordRexExp.hasMatch(val)) {
return 'Please enter a valid password';
}
return null;
},
suffixIcon: IconButton(
onPressed: () {
setState(() {
obscurePassword = !obscurePassword;
if (obscurePassword) {
iconPassword = CupertinoIcons.eye_fill;
} else {
iconPassword = CupertinoIcons.eye_slash_fill;
}
});
}, },
icon: Icon(iconPassword, color: Colors.grey[600]), suffixIcon: IconButton(
onPressed: () {
setState(() {
obscurePassword = !obscurePassword;
if (obscurePassword) {
iconPassword = CupertinoIcons.eye_fill;
} else {
iconPassword = CupertinoIcons.eye_slash_fill;
}
});
},
icon: Icon(iconPassword, color: Colors.grey[600]),
),
), ),
), ),
), const SizedBox(height: 20),
const SizedBox(height: 20), !signInRequired
!signInRequired ? SizedBox(
? SizedBox( width: MediaQuery.of(context).size.width * 0.9,
width: MediaQuery.of(context).size.width * 0.9, height: 50,
height: 50, child: TextButton(
child: TextButton( onPressed: () {
onPressed: () { if (_formKey.currentState!.validate()) {
if (_formKey.currentState!.validate()) { context.read<SignInBloc>().add(SignInRequired(
context.read<SignInBloc>().add(SignInRequired( emailController.text,
emailController.text, passwordController.text)); passwordController.text));
} }
}, },
style: TextButton.styleFrom( style: TextButton.styleFrom(
elevation: 3.0, elevation: 3.0,
backgroundColor: backgroundColor:
Theme.of(context).colorScheme.primary, Theme.of(context).colorScheme.primary,
foregroundColor: Colors.white, foregroundColor: Colors.white,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(60))), borderRadius: BorderRadius.circular(60))),
child: const Padding( child: const Padding(
padding: padding: EdgeInsets.symmetric(
EdgeInsets.symmetric(horizontal: 25, vertical: 5), horizontal: 25, vertical: 5),
child: Text( child: Text(
'Iniciar Sesión', 'Iniciar Sesión',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
),
), ),
), ),
), ),
), )
) : const CircularProgressIndicator()
: const CircularProgressIndicator() ],
], ),
)), ),
],
),
); );
} }
} }
+107 -80
View File
@@ -32,89 +32,116 @@ class _SignScreenState extends State<SignScreen> with TickerProviderStateMixin {
Widget build(BuildContext context) { Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width; double width = MediaQuery.of(context).size.width;
return BlocListener<AuthenticationBloc, AuthenticationState>( return BlocListener<AuthenticationBloc, AuthenticationState>(
listener: (context, state) { listener: (context, state) {
if (state.status == AuthenticationStatus.authenticated) { if (state.status == AuthenticationStatus.authenticated) {
Navigator.pop(context); Navigator.pop(context);
} }
}, },
child: Scaffold( child: Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.tertiary, backgroundColor: Theme.of(context).colorScheme.tertiary,
), body: Column(
body: Column( crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Text('${context.read<SignInBloc>().state}'), Padding(
Container( padding: const EdgeInsets.symmetric(vertical: 20),
color: Theme.of(context).colorScheme.tertiary, child: Center(
child: Column( child: Image(
children: [ width: width * 0.7,
Container( image: const AssetImage('images/logo_prosapp.png'),
color: Theme.of(context).colorScheme.tertiary,
padding: const EdgeInsets.only(bottom: 20.0),
child: Center(
child: Image(
width: width * 0.7,
image: const AssetImage('images/logo_prosapp.png'),
),
),
),
// TabBar(
// controller: tabController,
// unselectedLabelColor:
// Theme.of(context).colorScheme.onBackground,
// labelColor: Theme.of(context).colorScheme.onBackground,
// tabs: const [
// Padding(
// padding: EdgeInsets.all(12.0),
// child: Text(
// 'Inicia sesión',
// style: TextStyle(
// fontSize: 18,
// ),
// ),
// ),
// Padding(
// padding: EdgeInsets.all(12.0),
// child: Text(
// 'Registrate',
// style: TextStyle(
// fontSize: 18,
// ),
// ),
// ),
// ],
// ),
],
),
),
Expanded(
child: SingleChildScrollView(
child: SizedBox(
height: MediaQuery.of(context).size.height,
child: Column(
children: [
Expanded(
child: TabBarView(controller: tabController, children: [
BlocProvider<SignInBloc>(
create: (context) =>
Injector.appInstance.get<SignInBloc>(),
child: SignInScreen(),
),
BlocProvider<SignUpBloc>(
create: (context) =>
Injector.appInstance.get<SignUpBloc>(),
child: SignUpScreen(),
),
]),
)
],
), ),
), ),
), ),
), Expanded(
], child: Container(
), decoration: const BoxDecoration(
), color: Colors.white,
); borderRadius: BorderRadius.only(
topLeft: Radius.circular(60),
topRight: Radius.circular(60),
),
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 30, vertical: 15),
child: SingleChildScrollView(
child: SizedBox(
height: MediaQuery.of(context).size.height - 200,
child: TabBarView(
controller: tabController,
children: [
BlocProvider<SignInBloc>(
create: (context) =>
Injector.appInstance.get<SignInBloc>(),
child: SignInScreen(),
),
BlocProvider<SignUpBloc>(
create: (context) =>
Injector.appInstance.get<SignUpBloc>(),
child: SignUpScreen(),
),
],
),
),
),
),
),
)
],
),
)
// Scaffold(
// // appBar: AppBar(
// // backgroundColor: Theme.of(context).colorScheme.tertiary,
// // ),
// body: Column(
// children: [
// // Text('${context.read<SignInBloc>().state}'),
// Container(
// color: Theme.of(context).colorScheme.tertiary,
// child: Column(
// children: [
// Container(
// color: Theme.of(context).colorScheme.tertiary,
// padding: const EdgeInsets.only(bottom: 20.0),
// child: Center(
// child: Image(
// width: width * 0.7,
// image: const AssetImage('images/logo_prosapp.png'),
// ),
// ),
// ),
// ],
// ),
// ),
// Expanded(
// child: SingleChildScrollView(
// child: SizedBox(
// height: MediaQuery.of(context).size.height,
// child: Column(
// children: [
// Expanded(
// child: TabBarView(controller: tabController, children: [
// BlocProvider<SignInBloc>(
// create: (context) =>
// Injector.appInstance.get<SignInBloc>(),
// child: SignInScreen(),
// ),
// BlocProvider<SignUpBloc>(
// create: (context) =>
// Injector.appInstance.get<SignUpBloc>(),
// child: SignUpScreen(),
// ),
// ]),
// )
// ],
// ),
// ),
// ),
// ),
// ],
// ),
// ),
);
} }
} }
+211 -191
View File
@@ -1,6 +1,7 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:prosappco/components/general_primary_button.dart';
import 'package:user_repository/user_repository.dart'; import 'package:user_repository/user_repository.dart';
import '../../blocs/sign_up_bloc/sign_up_bloc.dart'; import '../../blocs/sign_up_bloc/sign_up_bloc.dart';
@@ -31,6 +32,8 @@ class _SignUpScreenState extends State<SignUpScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final width = MediaQuery.of(context).size.width;
return BlocListener<SignUpBloc, SignUpState>( return BlocListener<SignUpBloc, SignUpState>(
listener: (context, state) { listener: (context, state) {
if (state is SignUpSuccess) { if (state is SignUpSuccess) {
@@ -45,178 +48,212 @@ class _SignUpScreenState extends State<SignUpScreen> {
return; return;
} }
}, },
child: Scaffold( child: Column(
body: Form( children: [
key: _formKey, SizedBox(
child: Center( width: double.infinity,
child: Column( child: Row(
children: [ children: [
const SizedBox(height: 20), IconButton(
SizedBox( onPressed: () {
width: MediaQuery.of(context).size.width * 0.9, Navigator.pop(context);
child: MyTextField( },
controller: emailController, icon: const Icon(
hintText: 'Email', CupertinoIcons.arrow_left,
obscureText: false, size: 30,
keyboardType: TextInputType.emailAddress, ),
prefixIcon: const Icon(CupertinoIcons.mail_solid),
validator: (val) {
if (val!.isEmpty) {
return 'Please fill in this field';
} else if (!emailRexExp.hasMatch(val)) {
return 'Please enter a valid email';
}
return null;
}),
), ),
const SizedBox(height: 10), Text(
SizedBox( 'Registrate',
width: MediaQuery.of(context).size.width * 0.9, style: TextStyle(
child: MyTextField( // fontSize: 30,
controller: passwordController, fontSize: width * 0.08,
hintText: 'Password', fontWeight: FontWeight.bold,
obscureText: obscurePassword, ),
keyboardType: TextInputType.visiblePassword, ),
prefixIcon: const Icon(CupertinoIcons.lock_fill), ],
onChanged: (val) { ),
if (val!.contains(RegExp(r'[A-Z]'))) { ),
setState(() { Form(
containsUpperCase = true; key: _formKey,
}); child: Center(
} else { child: Column(
setState(() { children: [
containsUpperCase = false; const SizedBox(height: 20),
}); SizedBox(
} width: MediaQuery.of(context).size.width * 0.9,
if (val.contains(RegExp(r'[a-z]'))) { child: MyTextField(
setState(() { controller: emailController,
containsLowerCase = true; hintText: 'Email',
}); obscureText: false,
} else { keyboardType: TextInputType.emailAddress,
setState(() { prefixIcon: const Icon(CupertinoIcons.mail_solid),
containsLowerCase = false; validator: (val) {
}); if (val!.isEmpty) {
} return 'Please fill in this field';
if (val.contains(RegExp(r'[0-9]'))) { } else if (!emailRexExp.hasMatch(val)) {
setState(() { return 'Please enter a valid email';
containsNumber = true; }
}); return null;
} else { }),
setState(() { ),
containsNumber = false; const SizedBox(height: 10),
}); SizedBox(
} width: MediaQuery.of(context).size.width * 0.9,
if (val.contains(specialCharRexExp)) { child: MyTextField(
setState(() { controller: passwordController,
containsSpecialChar = true; hintText: 'Password',
}); obscureText: obscurePassword,
} else { keyboardType: TextInputType.visiblePassword,
setState(() { prefixIcon: const Icon(CupertinoIcons.lock_fill),
containsSpecialChar = false; onChanged: (val) {
}); if (val!.contains(RegExp(r'[A-Z]'))) {
} setState(() {
if (val.length >= 8) { containsUpperCase = true;
setState(() { });
contains8Length = true; } else {
}); setState(() {
} else { containsUpperCase = false;
setState(() { });
contains8Length = false; }
}); if (val.contains(RegExp(r'[a-z]'))) {
} setState(() {
return null; containsLowerCase = true;
}, });
suffixIcon: IconButton( } else {
onPressed: () { setState(() {
setState(() { containsLowerCase = false;
obscurePassword = !obscurePassword; });
if (obscurePassword) { }
iconPassword = CupertinoIcons.eye_fill; if (val.contains(RegExp(r'[0-9]'))) {
} else { setState(() {
iconPassword = CupertinoIcons.eye_slash_fill; containsNumber = true;
} });
}); } else {
setState(() {
containsNumber = false;
});
}
if (val.contains(specialCharRexExp)) {
setState(() {
containsSpecialChar = true;
});
} else {
setState(() {
containsSpecialChar = false;
});
}
if (val.length >= 8) {
setState(() {
contains8Length = true;
});
} else {
setState(() {
contains8Length = false;
});
}
return null;
}, },
icon: Icon(iconPassword), suffixIcon: IconButton(
onPressed: () {
setState(() {
obscurePassword = !obscurePassword;
if (obscurePassword) {
iconPassword = CupertinoIcons.eye_fill;
} else {
iconPassword = CupertinoIcons.eye_slash_fill;
}
});
},
icon: Icon(iconPassword),
),
validator: (val) {
if (val!.isEmpty) {
return 'Please fill in this field';
} else if (!passwordRexExp.hasMatch(val)) {
return 'Please enter a valid password';
}
return null;
}),
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"⚈ 1 uppercase",
style: TextStyle(
color: containsUpperCase
? Colors.green
: Theme.of(context)
.colorScheme
.onBackground),
),
Text(
"⚈ 1 lowercase",
style: TextStyle(
color: containsLowerCase
? Colors.green
: Theme.of(context)
.colorScheme
.onBackground),
),
],
), ),
validator: (val) { Column(
if (val!.isEmpty) { crossAxisAlignment: CrossAxisAlignment.start,
return 'Please fill in this field'; children: [
} else if (!passwordRexExp.hasMatch(val)) { Text(
return 'Please enter a valid password'; "⚈ 8 minimum character",
} style: TextStyle(
return null; color: contains8Length
}), ? Colors.green
), : Theme.of(context)
const SizedBox(height: 10), .colorScheme
Row( .onBackground),
mainAxisAlignment: MainAxisAlignment.spaceEvenly, ),
crossAxisAlignment: CrossAxisAlignment.start, Text(
children: [ "⚈ 1 number",
Column( style: TextStyle(
crossAxisAlignment: CrossAxisAlignment.start, color: containsNumber
children: [ ? Colors.green
Text( : Theme.of(context)
"⚈ 1 uppercase", .colorScheme
style: TextStyle( .onBackground),
color: containsUpperCase ),
? Colors.green ],
: Theme.of(context).colorScheme.onBackground), ),
), ],
Text( ),
"⚈ 1 lowercase", const SizedBox(height: 10),
style: TextStyle( SizedBox(
color: containsLowerCase width: MediaQuery.of(context).size.width * 0.9,
? Colors.green child: MyTextField(
: Theme.of(context).colorScheme.onBackground), labelText: 'Nombre',
), controller: nameController,
], hintText: 'Ingresa tu nombre',
), obscureText: false,
Column( keyboardType: TextInputType.name,
crossAxisAlignment: CrossAxisAlignment.start, prefixIcon: const Icon(CupertinoIcons.person_fill),
children: [ validator: (val) {
Text( if (val!.isEmpty) {
"⚈ 8 minimum character", return 'Please fill in this field';
style: TextStyle( } else if (val.length > 30) {
color: contains8Length return 'Name too long';
? Colors.green }
: Theme.of(context).colorScheme.onBackground), return null;
), }),
Text( ),
"⚈ 1 number", SizedBox(height: MediaQuery.of(context).size.height * 0.02),
style: TextStyle( !signUpRequired
color: containsNumber ? SizedBox(
? Colors.green width: MediaQuery.of(context).size.width * 0.5,
: Theme.of(context).colorScheme.onBackground), child: GeneralPrimaryButton(
), label: 'Registrarme',
],
),
],
),
const SizedBox(height: 10),
SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: MyTextField(
labelText: 'Nombre',
controller: nameController,
hintText: 'Ingresa tu nombre',
obscureText: false,
keyboardType: TextInputType.name,
prefixIcon: const Icon(CupertinoIcons.person_fill),
validator: (val) {
if (val!.isEmpty) {
return 'Please fill in this field';
} else if (val.length > 30) {
return 'Name too long';
}
return null;
}),
),
SizedBox(height: MediaQuery.of(context).size.height * 0.02),
!signUpRequired
? SizedBox(
width: MediaQuery.of(context).size.width * 0.5,
child: TextButton(
onPressed: () { onPressed: () {
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
MyUser myUser = MyUser.empty; MyUser myUser = MyUser.empty;
@@ -231,31 +268,14 @@ class _SignUpScreenState extends State<SignUpScreen> {
}); });
} }
}, },
style: TextButton.styleFrom( ),
elevation: 3.0, )
backgroundColor: : const CircularProgressIndicator(),
Theme.of(context).colorScheme.primary, ],
foregroundColor: Colors.white, ),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(60))),
child: const Padding(
padding: EdgeInsets.symmetric(
horizontal: 25, vertical: 5),
child: Text(
'Sign Up',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w600),
),
)),
)
: const CircularProgressIndicator(),
],
), ),
), ),
), ],
), ),
); );
} }
+20 -3
View File
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:intl_phone_field/intl_phone_field.dart'; import 'package:intl_phone_field/intl_phone_field.dart';
import 'package:prosappco/components/general_input_decoration.dart'; import 'package:prosappco/components/general_input_decoration.dart';
import 'package:prosappco/components/general_primary_button.dart';
import 'package:prosappco/screens/authentication/otp_auth_screen.dart'; import 'package:prosappco/screens/authentication/otp_auth_screen.dart';
import 'package:prosappco/screens/authentication/sign_screen.dart'; import 'package:prosappco/screens/authentication/sign_screen.dart';
@@ -100,7 +101,7 @@ class WelcomeScreen extends StatelessWidget {
color: Theme.of(context).colorScheme.onBackground, color: Theme.of(context).colorScheme.onBackground,
), ),
), ),
ElevatedButton( GeneralPrimaryButton(
onPressed: () { onPressed: () {
final phoneNumber = _phoneNumber; final phoneNumber = _phoneNumber;
@@ -112,10 +113,26 @@ class WelcomeScreen extends StatelessWidget {
OtpAuthScreen(phoneNumber: phoneNumber), OtpAuthScreen(phoneNumber: phoneNumber),
), ),
); );
} else {} }
}, },
child: const Text('Enviar código'), label: 'Enviar código',
), ),
// ElevatedButton(
// onPressed: () {
// final phoneNumber = _phoneNumber;
// if (phoneNumber != null && phoneNumber.isNotEmpty) {
// Navigator.push(
// context,
// CupertinoPageRoute(
// builder: (context) =>
// OtpAuthScreen(phoneNumber: phoneNumber),
// ),
// );
// } else {}
// },
// child: const Text('Enviar código'),
// ),
TextButton( TextButton(
onPressed: () { onPressed: () {
Navigator.push( Navigator.push(
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
class ProfileItem extends StatelessWidget {
final String title;
final String? subtitle;
final IconData? leading;
final VoidCallback onTap;
const ProfileItem({
super.key,
required this.title,
this.subtitle,
this.leading,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return Card(
margin: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
color: Colors.grey.shade100,
child: ListTile(
title: Text(
title,
style: const TextStyle(color: Colors.black),
),
subtitle: subtitle == null
? null
: Text(
subtitle ?? '',
style: const TextStyle(color: Colors.black),
),
leading: leading == null
? null
: Icon(
leading,
color: Colors.black,
),
trailing: const Icon(
Icons.keyboard_arrow_right,
color: Colors.black,
),
onTap: onTap,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
),
);
}
}
@@ -0,0 +1,137 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
class ProfileEmailScreen extends StatefulWidget {
const ProfileEmailScreen({super.key});
@override
State<ProfileEmailScreen> createState() => _ProfileEmailScreenState();
}
class _ProfileEmailScreenState extends State<ProfileEmailScreen> {
final TextEditingController _emailController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
@override
void dispose() {
_emailController.dispose();
_passwordController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return BlocBuilder<MyUserBloc, MyUserState>(
builder: (context, state) {
if (state.status == MyUserStatus.success) {
_emailController.text = state.user!.email ?? '';
return Scaffold(
appBar: AppBar(
title: Text(
_emailController.text.isEmpty
? 'Agregar correo'
: 'Actualizar 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),
),
),
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: 30),
ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
padding: const EdgeInsets.symmetric(vertical: 5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
shadowColor: Colors.grey,
elevation: 5,
),
child: Container(
constraints: const BoxConstraints(
maxWidth: 300.0, minHeight: 50.0),
alignment: Alignment.center,
child: const Text(
'Actualizar',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
),
),
),
);
} else {
return const Center(child: CircularProgressIndicator());
}
},
);
}
}
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
class ProfilePhoneScreen extends StatefulWidget {
const ProfilePhoneScreen({super.key});
@override
State<ProfilePhoneScreen> createState() => _ProfilePhoneScreenState();
}
class _ProfilePhoneScreenState extends State<ProfilePhoneScreen> {
final TextEditingController _phoneController = TextEditingController();
@override
void dispose() {
_phoneController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return BlocBuilder<MyUserBloc, MyUserState>(
builder: (context, state) {
if (state.status == MyUserStatus.success) {
_phoneController.text = state.user!.phone ?? '';
return Scaffold(
appBar: AppBar(
title: Text(
_phoneController.text.isEmpty
? 'Agregar telefono'
: 'Actualizar telefono',
),
),
body: const Placeholder(),
);
} else {
return const Center(child: CircularProgressIndicator());
}
},
);
}
}
+369 -133
View File
@@ -1,14 +1,18 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:injector/injector.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:prosappco/blocs/auth_bloc/auth_bloc.dart';
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart'; import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
import 'package:prosappco/blocs/profile_bloc/profile_bloc.dart'; import 'package:prosappco/blocs/profile_bloc/profile_bloc.dart';
import 'package:prosappco/components/birthday_picker.dart'; import 'package:prosappco/components/birthday_picker.dart';
import 'package:prosappco/components/gender_dropdown.dart'; import 'package:prosappco/components/gender_dropdown.dart';
import 'package:prosappco/src/components/pop_appbar.dart'; import 'package:prosappco/screens/profile/components/profile_item.dart';
import 'package:prosappco/screens/profile/profile_email_screen.dart';
import 'package:prosappco/screens/profile/profile_phone_screen.dart';
class ProfileScreen extends StatefulWidget { class ProfileScreen extends StatefulWidget {
const ProfileScreen({super.key}); const ProfileScreen({super.key});
@@ -20,13 +24,19 @@ class ProfileScreen extends StatefulWidget {
class _ProfileScreenState extends State<ProfileScreen> { class _ProfileScreenState extends State<ProfileScreen> {
final TextEditingController _nameController = TextEditingController(); final TextEditingController _nameController = TextEditingController();
final TextEditingController _emailController = TextEditingController(); final TextEditingController _emailController = TextEditingController();
final TextEditingController _newEmailController = TextEditingController();
final TextEditingController _phoneController = TextEditingController(); final TextEditingController _phoneController = TextEditingController();
final TextEditingController _birthdayController = TextEditingController(); final TextEditingController _birthdayController = TextEditingController();
final TextEditingController _genderController = TextEditingController(); final TextEditingController _genderController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
XFile? _imageFile; XFile? _imageFile;
bool isLoading = false; bool isLoading = false;
bool enableLoginWithEmail = false;
bool obscurePassword = true;
IconData iconPassword = CupertinoIcons.eye_fill;
@override @override
void dispose() { void dispose() {
_nameController.dispose(); _nameController.dispose();
@@ -34,149 +44,356 @@ class _ProfileScreenState extends State<ProfileScreen> {
_phoneController.dispose(); _phoneController.dispose();
_birthdayController.dispose(); _birthdayController.dispose();
_genderController.dispose(); _genderController.dispose();
_passwordController.dispose();
_newEmailController.dispose();
super.dispose(); super.dispose();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocListener<ProfileBloc, ProfileState>( final authBloc = Injector.appInstance.get<AuthBloc>();
listener: (context, state) {
if (state is UpdateUserInfoLoading) {
setState(() {
isLoading = true;
});
} else if (state is UpdateUserInfoSuccess) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Información actualizada'),
));
setState(() {
isLoading = false;
});
} else if (state is UpdateUserInfoFailure) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Error al actualizar la información'),
));
setState(() {
isLoading = false;
});
}
},
child: Scaffold(
appBar: PopAppbar(
onPressed: () {
Navigator.pop(context);
},
label: 'Perfil',
),
body: BlocBuilder<MyUserBloc, MyUserState>(
builder: (context, state) {
if (state.status == MyUserStatus.success) {
_nameController.text = state.user!.name ?? '';
_emailController.text = state.user!.email ?? '';
_phoneController.text = state.user!.phone ?? '';
_birthdayController.text = state.user!.birthday ?? '';
_genderController.text = state.user!.gender ?? '';
return SingleChildScrollView( return BlocProvider<AuthBloc>(
child: Padding( create: (context) => authBloc,
padding: child: BlocListener<ProfileBloc, ProfileState>(
const EdgeInsets.symmetric(horizontal: 40, vertical: 20), listener: (context, state) {
child: Stack( if (state is UpdateUserInfoLoading) {
children: [ setState(() {
Column( isLoading = true;
crossAxisAlignment: CrossAxisAlignment.stretch, });
children: [ } else if (state is UpdateUserInfoSuccess) {
pictureWidget(state, context), ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
const SizedBox(height: 20.0), content: Text('Información actualizada'),
TextFormField( ));
controller: _nameController, setState(() {
decoration: const InputDecoration( isLoading = false;
labelText: 'Nombre', });
prefixIcon: Icon(Icons.person), } else if (state is UpdateUserInfoFailure) {
hintText: 'Nombre (obligatorio)', ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
border: OutlineInputBorder( content: Text('Error al actualizar la información'),
borderRadius: BorderRadius.all( ));
Radius.circular(10.0), setState(() {
)), isLoading = false;
errorBorder: OutlineInputBorder( });
borderSide: BorderSide(color: Colors.red), }
), },
focusedErrorBorder: OutlineInputBorder( child: Scaffold(
borderSide: appBar: AppBar(
BorderSide(color: Colors.red, width: 2.0), title: const Text('Perfil'),
), ),
body: BlocBuilder<MyUserBloc, MyUserState>(
builder: (context, state) {
if (state.status == MyUserStatus.success) {
_nameController.text = state.user!.name ?? '';
_emailController.text = state.user!.email ?? '';
_phoneController.text = state.user!.phone ?? '';
_birthdayController.text = state.user!.birthday ?? '';
_genderController.text = state.user!.gender ?? '';
return SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 40, vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
pictureWidget(state, context),
const SizedBox(height: 30),
TextFormField(
controller: _nameController,
decoration: const InputDecoration(
labelText: 'Nombre',
prefixIcon: Icon(Icons.person),
hintText: 'Nombre (obligatorio)',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10.0),
)),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
), ),
validator: (value) { focusedErrorBorder: OutlineInputBorder(
if (value == null || value.isEmpty) { borderSide:
return 'Por favor, ingrese su nombre'; BorderSide(color: Colors.red, width: 2.0),
}
return null;
},
),
const SizedBox(height: 20.0),
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),
),
), ),
), ),
const SizedBox(height: 20.0), validator: (value) {
TextFormField( if (value == null || value.isEmpty) {
controller: _phoneController, return 'Por favor, ingrese su nombre';
decoration: const InputDecoration( }
labelText: 'Número de Teléfono', return null;
prefixIcon: Icon(Icons.phone_android_rounded), },
hintText: '+57', ),
border: OutlineInputBorder( const SizedBox(height: 20),
borderRadius: BorderRadius.all( ProfileItem(
Radius.circular(10.0), title: 'Iniciar sesión con correo',
)), subtitle: _emailController.text,
errorBorder: OutlineInputBorder( leading: Icons.email_rounded,
borderSide: BorderSide(color: Colors.red), onTap: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) =>
const ProfileEmailScreen(),
), ),
focusedErrorBorder: OutlineInputBorder( );
borderSide: },
BorderSide(color: Colors.red, width: 2.0), ),
const SizedBox(height: 20),
ProfileItem(
title: 'Iniciar sesión con teléfono',
subtitle: _phoneController.text,
leading: Icons.phone_iphone_rounded,
onTap: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) =>
const ProfilePhoneScreen(),
), ),
), );
), },
const SizedBox(height: 20.0), ),
BirthdayPicker(
onDateSelected: (birthDay) { // Column(
_birthdayController.text = // children: [
DateFormat('dd/MM/yyyy').format(birthDay); // const SizedBox(height: 20.0),
}, // TextFormField(
controller: _birthdayController, // readOnly: true,
), // controller: _emailController,
const SizedBox(height: 20.0), // decoration: const InputDecoration(
GenderDropdown( // labelText: 'Email',
controller: _genderController, // prefixIcon: Icon(Icons.email_rounded),
), // hintText: 'Email',
const SizedBox(height: 60.0), // border: OutlineInputBorder(
saveButton(state, context), // borderRadius: BorderRadius.all(
], // Radius.circular(10.0),
), // )),
], // errorBorder: OutlineInputBorder(
// borderSide: BorderSide(color: Colors.red),
// ),
// focusedErrorBorder: OutlineInputBorder(
// borderSide: BorderSide(
// color: Colors.red, width: 2.0),
// ),
// ),
// ),
// ],
// ),
// const SizedBox(height: 20.0),
// TextFormField(
// readOnly: true,
// controller: _phoneController,
// decoration: const InputDecoration(
// labelText: 'Número de Teléfono',
// prefixIcon: Icon(Icons.phone_android_rounded),
// hintText: '+57',
// 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),
// ),
// ),
// ),
// _emailController.text.isEmpty
// ? Column(
// children: [
// const SizedBox(height: 20.0),
// GeneralCheckbox(
// text:
// 'Habilitar inicio de sesión con correo (Opcional)',
// initialValue: enableLoginWithEmail,
// onChanged: (value) {
// setState(() {
// enableLoginWithEmail = value;
// });
// },
// ),
// enableLoginWithEmail
// ? Container(
// decoration: BoxDecoration(
// border: Border.all(
// color: Colors.blue,
// width: 0.5,
// ),
// borderRadius:
// BorderRadius.circular(10),
// ),
// padding: const EdgeInsets.all(10),
// child: Column(
// children: [
// TextFormField(
// controller:
// _newEmailController,
// validator: (String? value) {
// if (enableLoginWithEmail) {
// if (value == null ||
// value.isEmpty) {
// return 'Por favor ingrese un email';
// }
// final RegExp
// emailRegExp =
// RegExp(
// r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
// if (!emailRegExp
// .hasMatch(value)) {
// return 'Por favor ingrese un email válido';
// }
// return null;
// } else {
// return null;
// }
// },
// decoration:
// const InputDecoration(
// prefixIcon: Icon(
// Icons.email_rounded),
// hintText: 'Email',
// ),
// ),
// const SizedBox(height: 20.0),
// TextFormField(
// controller:
// _passwordController,
// obscureText:
// obscurePassword,
// validator: (value) {
// if (enableLoginWithEmail) {
// if (value == null ||
// value.isEmpty) {
// return 'Por favor ingrese una contraseña.';
// }
// if (value.length < 5) {
// return 'Debe tener al menos 5 caracteres.';
// }
// return null;
// } else {
// return null;
// }
// },
// decoration: InputDecoration(
// prefixIcon: const Icon(
// Icons.lock_rounded),
// suffixIcon: IconButton(
// onPressed: () {
// setState(() {
// obscurePassword =
// !obscurePassword;
// if (obscurePassword) {
// iconPassword =
// CupertinoIcons
// .eye_fill;
// } else {
// iconPassword =
// CupertinoIcons
// .eye_slash_fill;
// }
// });
// },
// icon: Icon(iconPassword,
// color: Colors
// .grey[600]),
// ),
// hintText: 'Contraseña',
// ),
// ),
// const SizedBox(height: 20),
// Container(
// margin:
// const EdgeInsets.only(
// left: 5,
// right: 5,
// top: 5,
// bottom: 5,
// ),
// padding: const EdgeInsets
// .symmetric(
// horizontal: 10,
// vertical: 8,
// ),
// decoration: BoxDecoration(
// color: const Color(
// 0xFFD6F4FF),
// borderRadius:
// BorderRadius.circular(
// 20),
// boxShadow: [
// BoxShadow(
// color: Colors.grey
// .withOpacity(0.5),
// spreadRadius: 1,
// blurRadius: 5,
// offset: const Offset(
// 1, 3),
// ),
// ],
// ),
// child: const Row(
// children: [
// Icon(
// Icons.error_outline,
// size: 20,
// color: Colors.black54,
// ),
// SizedBox(width: 10),
// Expanded(
// child: Text(
// 'Al habilitar el inicio de sesión con correo, se cerrara la sesión actual.',
// style: TextStyle(
// color: Colors
// .black54,
// fontSize: 13,
// ),
// ),
// ),
// ],
// ),
// )
// ],
// ),
// )
// : const SizedBox(),
// ],
// )
// : const SizedBox(),
_birthdayController.text.isEmpty &&
_genderController.text.isEmpty
? Column(
children: [
const SizedBox(height: 20.0),
BirthdayPicker(
onDateSelected: (birthDay) {
_birthdayController.text =
DateFormat('dd/MM/yyyy')
.format(birthDay);
},
controller: _birthdayController,
),
const SizedBox(height: 20.0),
GenderDropdown(
controller: _genderController,
),
],
)
: const SizedBox(),
const SizedBox(height: 60.0),
saveButton(state, context),
],
),
), ),
), );
); } else {
} else { return const Center(child: CircularProgressIndicator());
return const Center(child: CircularProgressIndicator()); }
} },
}, ),
), ),
), ),
); );
@@ -189,6 +406,25 @@ class _ProfileScreenState extends State<ProfileScreen> {
return; return;
} }
if (enableLoginWithEmail) {
if (_newEmailController.text.isEmpty) {
return;
}
if (_passwordController.text.isEmpty) {
return;
}
context.read<AuthBloc>().add(
AuthEventAddEmailAndPassword(
email: _newEmailController.text,
password: _passwordController.text,
),
);
_emailController.text = _newEmailController.text;
}
final myUser = state.user!.copyWith( final myUser = state.user!.copyWith(
name: _nameController.text, name: _nameController.text,
email: _emailController.text, email: _emailController.text,
@@ -209,7 +445,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
}, },
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue, backgroundColor: Colors.blue,
padding: const EdgeInsets.symmetric(vertical: 15), padding: const EdgeInsets.symmetric(vertical: 5),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
), ),
@@ -374,6 +374,25 @@ class _ProfileScreenState extends State<ProfileScreen> {
); );
} }
Future<bool> updateEmailAndPassword(String email, String password) async {
final User? user = FirebaseAuth.instance.currentUser;
if (user != null) {
try {
await user.updateEmail(email);
await user.updatePassword(password);
return true;
} catch (e) {
WarningSnackbar.show(
title: 'Inicia sesión de nuevo',
message: 'Inicia la sesión de nuevo para guardar los cambios.',
);
AuthenticationRepository.instance.logout(uid!);
}
}
return false;
}
Future<void> _updateEmailAndPassword( Future<void> _updateEmailAndPassword(
String newEmail, String currentPassword) async { String newEmail, String currentPassword) async {
final user = _auth.currentUser; final user = _auth.currentUser;
@@ -502,24 +521,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
); );
} }
Future<bool> updateEmailAndPassword(String email, String password) async {
final User? user = FirebaseAuth.instance.currentUser;
if (user != null) {
try {
await user.updateEmail(email);
await user.updatePassword(password);
return true;
} catch (e) {
WarningSnackbar.show(
title: 'Inicia sesión de nuevo',
message: 'Inicia la sesión de nuevo para guardar los cambios.',
);
AuthenticationRepository.instance.logout(uid!);
}
}
return false;
}
bool enableLoginWithEmail = false; bool enableLoginWithEmail = false;
@@ -164,6 +164,25 @@ class FirebaseUserRepository implements UserRepository {
} }
} }
// Add email and password to user authenticate with phone
@override
Future<bool> addEmailAndPassword(String email, String password) async {
try {
await _firebaseAuth.currentUser!.updateEmail(email);
await _firebaseAuth.currentUser!.updatePassword(password);
return true;
} catch (e) {
log('xd -- Error add email and password ${e.toString()}');
if (e is FirebaseAuthException && e.code == 'requires-recent-login') {}
if (e is FirebaseAuthException && e.code == 'email-already-in-use') {}
return false;
}
}
// Sign out // Sign out
@override @override
Future<void> logOut() async { Future<void> logOut() async {
@@ -7,6 +7,8 @@ abstract class UserRepository {
Future<void> signIn(String email, String password); Future<void> signIn(String email, String password);
Future<bool> addEmailAndPassword(String email, String password);
Future<void> logOut(); Future<void> logOut();
// Future<MyUser> signUp(String name, String email, String password); // Future<MyUser> signUp(String name, String email, String password);