diff --git a/lib/src/screens/professional_profile.dart b/lib/src/screens/professional_profile.dart index e3cecf7..7081708 100644 --- a/lib/src/screens/professional_profile.dart +++ b/lib/src/screens/professional_profile.dart @@ -36,6 +36,8 @@ class ProfessionalProfileScreenState extends State { List images_especializacion = []; var _profession = '...'; var photoTemp = ''; + var photoCedulaTemp = ''; + var photoCertificadoTemp = ''; var _photo = '...'; @override @@ -208,40 +210,32 @@ class ProfessionalProfileScreenState extends State { final TaskSnapshot snapshot = await uploadTask.whenComplete(() => true); - photoTemp = ref.fullPath; + photoCedulaTemp = ref.fullPath; if (snapshot.state == TaskState.success) { + updateImageCedula(photoCedulaTemp); + return true; } else { return false; } } - Future> uploadEspecializaciones(List images) async { - List photoPaths = []; + Future updateImageCedula(image) async { + try { + final userRef = FirebaseFirestore.instance.collection('users').doc(uid); + final userSnapshot = await userRef.get(); - for (File image in images) { - final String namefile = image.path.split('/').last; - - Reference ref = storage - .ref() - .child('users') - .child(uid!) - .child('especializaciones') - .child(namefile); - - final UploadTask uploadTask = ref.putFile(image); - - final TaskSnapshot snapshot = await uploadTask.whenComplete(() => true); - - photoPaths.add(ref.fullPath); - - if (snapshot.state != TaskState.success) { - return []; + if (userSnapshot.exists) { + await userRef.update({'imgCedula': image}); + print('¡Imagen de cédula actualizada correctamente!'); + } else { + await userRef.set({'imgCedula': image}); + print('¡Imagen de cédula agregada correctamente!'); } + } catch (e) { + print('Error al agregar o actualizar la imagen de cédula: $e'); } - - return photoPaths; } Future uploadCertificado(File image) async { @@ -258,15 +252,34 @@ class ProfessionalProfileScreenState extends State { final TaskSnapshot snapshot = await uploadTask.whenComplete(() => true); - photoTemp = ref.fullPath; + photoCertificadoTemp = ref.fullPath; if (snapshot.state == TaskState.success) { + updateImageCertificado(photoCertificadoTemp); + return true; } else { return false; } } + Future updateImageCertificado(image) async { + try { + final userRef = FirebaseFirestore.instance.collection('users').doc(uid); + final userSnapshot = await userRef.get(); + + if (userSnapshot.exists) { + await userRef.update({'imgCertificado': image}); + print('¡Imagen de certificado actualizada correctamente!'); + } else { + await userRef.set({'imgCertificado': image}); + print('¡Imagen de certificado agregada correctamente!'); + } + } catch (e) { + print('Error al agregar o actualizar la imagen de certificado: $e'); + } + } + Future updateImage(image) async { try { await FirebaseFirestore.instance @@ -312,6 +325,55 @@ class ProfessionalProfileScreenState extends State { } } + Future> uploadEspecializaciones(List images) async { + List photoPaths = []; + + for (File image in images) { + final String namefile = image.path.split('/').last; + + Reference ref = storage + .ref() + .child('users') + .child(uid!) + .child('especializaciones') + .child(namefile); + + final UploadTask uploadTask = ref.putFile(image); + + final TaskSnapshot snapshot = await uploadTask.whenComplete(() => true); + + if (snapshot.state == TaskState.success) { + photoPaths.add(ref.fullPath); + } else { + updateImagesEspecializaciones(photoPaths); + return []; + } + } + + updateImagesEspecializaciones(photoPaths); + return photoPaths; + } + + Future updateImagesEspecializaciones(List photoPaths) async { + print('abc $photoPaths'); + + try { + final userRef = FirebaseFirestore.instance.collection('users').doc(uid); + final userSnapshot = await userRef.get(); + + if (userSnapshot.exists) { + await userRef.update({'imgEspecializaciones': photoPaths}); + print('¡Imágenes de especializaciones actualizadas correctamente!'); + } else { + await userRef.set({'imgEspecializaciones': photoPaths}); + print('¡Imágenes de especializaciones agregadas correctamente!'); + } + } catch (e) { + print( + 'Error al agregar o actualizar las imágenes de especializaciones: $e'); + } + } + Future sendInfo() async { final String cedula = _cedulaController.text.trim(); final String especializacion = _especializacionController.text.trim(); @@ -349,7 +411,6 @@ class ProfessionalProfileScreenState extends State { if (imagen_to_upload != null) { updateImage(photoTemp); } - // Navega a la siguiente pantalla Navigator.pushReplacementNamed(context, '/solicitudEnviada'); } diff --git a/lib/src/screens/profile.dart b/lib/src/screens/profile.dart index d98e894..bd16274 100644 --- a/lib/src/screens/profile.dart +++ b/lib/src/screens/profile.dart @@ -245,6 +245,7 @@ class _ProfileScreenState extends State { await FirebaseAuth.instance.currentUser!.updateDisplayName(newName); await FirebaseFirestore.instance.collection('users').doc(uid).update({ 'name': newName, + 'lowerName': newName.toLowerCase(), }); print('Nombre actualizado correctamente'); } catch (e) { @@ -254,6 +255,9 @@ class _ProfileScreenState extends State { if (currentUser?.email != newEmail) { if (newPassword.isNotEmpty) { + await FirebaseFirestore.instance.collection('users').doc(uid).update({ + 'email': newEmail, + }); updateEmailAndPassword(newEmail, newPassword); } else { Get.snackbar( @@ -439,6 +443,15 @@ class _ProfileScreenState extends State { : TextFormField( controller: _passwordController, obscureText: _obscureText, + validator: (value) { + if (value == null || value.isEmpty) { + return 'Porfavor ingrese una contraseña.'; + } + if (value.length < 5) { + return 'Debe tener al menos 5 caracteres.'; + } + return null; + }, decoration: InputDecoration( prefixIcon: const Icon(Icons.lock_outline), suffixIcon: IconButton(