This commit is contained in:
Felipe
2023-11-10 15:34:13 -05:00
parent b3d1740649
commit f732d461d0
14 changed files with 613 additions and 235 deletions
@@ -43,13 +43,14 @@ class _ProfileScreenState extends State<ProfileScreen> {
var _photo = '...';
String? _email = '';
String gender = '';
String genderDb = '';
DateTime? birthDate;
String birthDateDb = '';
@override
void initState() {
super.initState();
final uid = AuthenticationRepository.instance.getCurrentUserUid();
_auth = FirebaseAuth.instance;
final currentUser = _auth.currentUser;
@@ -65,22 +66,40 @@ class _ProfileScreenState extends State<ProfileScreen> {
_emailController.text = currentUser.email!;
}
if (gender.isEmpty) {
AuthenticationRepository.instance.getGender(uid.toString()).then(
(String s) => setState(() {
genderDb = s;
}),
);
}
if (birthDate == null) {
AuthenticationRepository.instance.getBirthday(uid.toString()).then(
(String s) => setState(() {
if (s.isNotEmpty) {
birthDateDb = s;
}
}),
);
}
_email = currentUser?.email;
if (_ciudad == '...') {
AuthenticationRepository.instance
.getCity(uid.toString())
.then((String s) => setState(() {
_ciudad = s;
}));
AuthenticationRepository.instance.getCity(uid.toString()).then(
(String s) => setState(() {
_ciudad = s;
}),
);
}
if (_photo == '...') {
AuthenticationRepository.instance
.getPhoto(uid.toString())
.then((String s) => setState(() {
_photo = s;
}));
AuthenticationRepository.instance.getPhoto(uid.toString()).then(
(String s) => setState(() {
_photo = s;
}),
);
}
}
@@ -221,6 +240,32 @@ class _ProfileScreenState extends State<ProfileScreen> {
String newEmail = _emailController.text.trim();
String newPassword = _passwordController.text.trim();
if (gender.isNotEmpty) {
try {
await FirebaseFirestore.instance.collection('users').doc(uid).set({
'gender': gender,
}, SetOptions(merge: true));
genderDb = gender;
} catch (e) {
print('Error al actualizar el genero: $e');
}
}
if (birthDate != null) {
try {
await FirebaseFirestore.instance.collection('users').doc(uid).set({
'birth_date': birthDate.toString(),
}, SetOptions(merge: true));
birthDateDb = birthDate.toString();
} catch (e) {
print('Error al actualizar la fecha de nacimiento: $e');
}
}
setState(() {});
if (newName.isEmpty) {
Get.snackbar(
'Nombre Invalido',
@@ -281,7 +326,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
.doc(uid)
.update({'email': newEmail});
} catch (e) {
print('e');
print('Error al actualizar la imagen de perfil $e');
}
try {
@@ -296,7 +341,11 @@ class _ProfileScreenState extends State<ProfileScreen> {
print('Error al actualizar la imagen de perfil $e');
}
// notifyListeners();
Get.snackbar(
'Informacion actualizada',
'Tu informacion ha sido actualizada con exito.',
snackPosition: SnackPosition.BOTTOM,
);
}
Future<void> _updateEmailAndPassword(
@@ -435,7 +484,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
'Inicia sesión para asegurarnos de que seas tú.',
snackPosition: SnackPosition.BOTTOM,
);
AuthenticationRepository.instance.logout(uid!);
// AuthenticationRepository.instance.logout(uid!);
}
}
}
@@ -644,26 +693,32 @@ class _ProfileScreenState extends State<ProfileScreen> {
),
),
const SizedBox(height: 20.0),
GenderDropdown(
onChanged: (selectedGender) {
setState(() {
gender = selectedGender;
});
},
),
const SizedBox(height: 20.0),
BirthDatePicker(
onDateSelected: (birthDay) {
setState(() {
birthDate = birthDay;
});
},
controller: TextEditingController(
text: birthDate == null
? ''
: formatter.format(birthDate!),
),
),
genderDb == ''
? GenderDropdown(
onChanged: (selectedGender) {
setState(() {
gender = selectedGender;
});
},
)
: const SizedBox(),
genderDb == ''
? const SizedBox(height: 20.0)
: const SizedBox(),
birthDateDb == ''
? BirthDatePicker(
onDateSelected: (birthDay) {
setState(() {
birthDate = birthDay;
});
},
controller: TextEditingController(
text: birthDate == null
? ''
: formatter.format(birthDate!),
),
)
: const SizedBox(),
],
),
),