update
This commit is contained in:
@@ -8,6 +8,7 @@ import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||
import 'package:prosappco/src/components/photo_view.dart';
|
||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||
import 'package:prosappco/src/controllers/info_%20professional.dart';
|
||||
import 'package:prosappco/src/presentation/widgets/shared/warning_snackbar.dart';
|
||||
import 'package:prosappco/src/services/select_image_profile.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
|
||||
@@ -187,7 +188,7 @@ class ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
|
||||
Reference ref =
|
||||
storage.ref().child('users').child(uid!).child('cedula').child(random);
|
||||
|
||||
final UploadTask uploadTask = ref.putFile(image);
|
||||
final UploadTask uploadTask = ref.putFile(image, metadata);
|
||||
|
||||
final TaskSnapshot snapshot = await uploadTask.whenComplete(() => true);
|
||||
|
||||
@@ -217,6 +218,10 @@ class ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
final metadata = SettableMetadata(
|
||||
contentType: 'application/pdf',
|
||||
);
|
||||
|
||||
Future<bool> uploadCertificado(File image) async {
|
||||
final now = DateTime.now();
|
||||
final formattedDate = DateFormat('HHmmssddMMyyyy').format(now);
|
||||
@@ -230,7 +235,7 @@ class ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
|
||||
.child('certificado_profesional')
|
||||
.child(random);
|
||||
|
||||
final UploadTask uploadTask = ref.putFile(image);
|
||||
final UploadTask uploadTask = ref.putFile(image, metadata);
|
||||
|
||||
final TaskSnapshot snapshot = await uploadTask.whenComplete(() => true);
|
||||
|
||||
@@ -281,24 +286,31 @@ class ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
|
||||
}
|
||||
|
||||
Future<bool> uploadImage(File image) async {
|
||||
final String namefile = image.path.split('/').last;
|
||||
try {
|
||||
final String namefile = image.path.split('/').last;
|
||||
|
||||
Reference ref = storage
|
||||
.ref()
|
||||
.child('users')
|
||||
.child(uid!)
|
||||
.child('profile')
|
||||
.child(namefile);
|
||||
Reference ref = storage
|
||||
.ref()
|
||||
.child('users')
|
||||
.child(uid!)
|
||||
.child('profile')
|
||||
.child(namefile);
|
||||
|
||||
final UploadTask uploadTask = ref.putFile(image);
|
||||
final UploadTask uploadTask = ref.putFile(image);
|
||||
|
||||
final TaskSnapshot snapshot = await uploadTask.whenComplete(() => true);
|
||||
final TaskSnapshot snapshot = await uploadTask;
|
||||
|
||||
photoTemp = ref.fullPath;
|
||||
if (snapshot.state == TaskState.success) {
|
||||
// Obtén la URL de descarga de la imagen y actualiza en Firestore
|
||||
String downloadURL = await ref.getDownloadURL();
|
||||
await updateImage(downloadURL);
|
||||
|
||||
if (snapshot.state == TaskState.success) {
|
||||
return true;
|
||||
} else {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error al cargar la imagen: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -361,7 +373,7 @@ class ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
|
||||
.child('especializaciones')
|
||||
.child('e${DateTime.now().millisecondsSinceEpoch}.pdf');
|
||||
|
||||
final UploadTask uploadTask = ref.putFile(image);
|
||||
final UploadTask uploadTask = ref.putFile(image, metadata);
|
||||
|
||||
final TaskSnapshot snapshot = await uploadTask.whenComplete(() => true);
|
||||
|
||||
@@ -419,22 +431,47 @@ class ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
|
||||
especializacion.split(',').map((e) => e.trim()).toList();
|
||||
|
||||
if (cedula.isEmpty) {
|
||||
_showCustomSnackBar(
|
||||
context, 'Por favor, adjunta el documento PDF de tu cédula.');
|
||||
WarningSnackbar.show(
|
||||
title: 'Te faltan campos!!',
|
||||
message: 'Por favor, ingresa tu cedula',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (image_cedula == null) {
|
||||
_showCustomSnackBar(
|
||||
context, 'Por favor, adjunte el documento PDF de su cédula.');
|
||||
WarningSnackbar.show(
|
||||
title: 'Te faltan archivos!!',
|
||||
message: 'Por favor, adjunta el documento PDF de tu cedula',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_profession.isEmpty) {
|
||||
WarningSnackbar.show(
|
||||
title: 'Te falta elegir una profesión!!',
|
||||
message:
|
||||
'Por favor, elige tu profesión antes de enviar la información.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (image_certificado == null) {
|
||||
_showCustomSnackBar(context,
|
||||
'Por favor, adjunta el documento PDF de tu certificado. ¡Gracias por tu colaboración!');
|
||||
WarningSnackbar.show(
|
||||
title: 'Te faltan archivos!!',
|
||||
message: 'Por favor, adjunta el documento PDF de tu certificado',
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (imagen_to_upload == null) {
|
||||
WarningSnackbar.show(
|
||||
title: 'Sube una foto de perfil',
|
||||
message: 'Para continuar debes subir una imagen de perfil',
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
// Actualiza la imagen de perfil si hay cambios
|
||||
updateImage(photoTemp);
|
||||
}
|
||||
|
||||
// Actualiza los datos del usuario en Firestore
|
||||
await FirebaseFirestore.instance.collection('users').doc(uid).update({
|
||||
@@ -448,11 +485,6 @@ class ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
|
||||
uploadCertificado(image_certificado!);
|
||||
uploadEspecializaciones(images_especializacion);
|
||||
|
||||
// Actualiza la imagen de perfil si hay cambios
|
||||
if (imagen_to_upload != null) {
|
||||
updateImage(photoTemp);
|
||||
}
|
||||
// Navega a la siguiente pantalla
|
||||
Navigator.pushReplacementNamed(context, '/solicitudEnviada');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user