subir y recoger pdf
This commit is contained in:
@@ -174,7 +174,7 @@ class _ProfessionalProfileWebScreenState
|
||||
if (uploadedPhotoPaths.isNotEmpty) {
|
||||
// Las imágenes se cargaron correctamente
|
||||
// Actualiza las imágenes en Firestore
|
||||
await updateImagesEspecializaciones(uploadedPhotoPaths);
|
||||
await updateFilesEspecializaciones(uploadedPhotoPaths);
|
||||
|
||||
// Navega a la siguiente pantalla
|
||||
Navigator.pushReplacementNamed(context, '/solicitudEnviada');
|
||||
@@ -310,31 +310,61 @@ class _ProfessionalProfileWebScreenState
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<String>> uploadEspecializaciones(List<Uint8List> images) async {
|
||||
List<String> photoPaths = [];
|
||||
// Future<List<String>> uploadEspecializaciones(List<Uint8List> images) async {
|
||||
// List<String> photoPaths = [];
|
||||
|
||||
for (Uint8List imageBytes in images) {
|
||||
Reference ref = storage
|
||||
// for (Uint8List imageBytes in images) {
|
||||
// Reference ref = storage
|
||||
// .ref()
|
||||
// .child('users')
|
||||
// .child(uid!)
|
||||
// .child('especializaciones')
|
||||
// .child('e${DateTime.now().millisecondsSinceEpoch}.jpg');
|
||||
|
||||
// final UploadTask uploadTask = ref.putData(imageBytes);
|
||||
|
||||
// final TaskSnapshot snapshot = await uploadTask.whenComplete(() => true);
|
||||
|
||||
// if (snapshot.state == TaskState.success) {
|
||||
// photoPaths.add(ref.fullPath);
|
||||
// } else {
|
||||
// await updateImagesEspecializaciones(photoPaths);
|
||||
// return [];
|
||||
// }
|
||||
// }
|
||||
|
||||
// await updateImagesEspecializaciones(photoPaths);
|
||||
// return photoPaths;
|
||||
// }
|
||||
|
||||
Future<List<String>> uploadEspecializaciones(List<Uint8List> files) async {
|
||||
List<String> filePaths = [];
|
||||
|
||||
for (Uint8List fileBytes in files) {
|
||||
final Reference ref = FirebaseStorage.instance
|
||||
.ref()
|
||||
.child('users')
|
||||
.child(uid!)
|
||||
.child('especializaciones')
|
||||
.child('e${DateTime.now().millisecondsSinceEpoch}.jpg');
|
||||
.child('e${DateTime.now().millisecondsSinceEpoch}.pdf');
|
||||
|
||||
final UploadTask uploadTask = ref.putData(imageBytes);
|
||||
final SettableMetadata metaData =
|
||||
SettableMetadata(contentType: 'application/pdf');
|
||||
|
||||
final UploadTask uploadTask = ref.putData(fileBytes, metaData);
|
||||
|
||||
final TaskSnapshot snapshot = await uploadTask.whenComplete(() => true);
|
||||
|
||||
if (snapshot.state == TaskState.success) {
|
||||
photoPaths.add(ref.fullPath);
|
||||
filePaths.add(ref.fullPath);
|
||||
} else {
|
||||
await updateImagesEspecializaciones(photoPaths);
|
||||
await updateFilesEspecializaciones(filePaths);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
await updateImagesEspecializaciones(photoPaths);
|
||||
return photoPaths;
|
||||
await updateFilesEspecializaciones(filePaths);
|
||||
return filePaths;
|
||||
}
|
||||
|
||||
Future<void> updateImageCedula(image) async {
|
||||
@@ -393,21 +423,41 @@ class _ProfessionalProfileWebScreenState
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateImagesEspecializaciones(List<String> photoPaths) async {
|
||||
// Future<void> updateImagesEspecializaciones(List<String> photoPaths) async {
|
||||
// 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<void> updateFilesEspecializaciones(List<String> filePaths) async {
|
||||
try {
|
||||
final userRef = FirebaseFirestore.instance.collection('users').doc(uid);
|
||||
final userSnapshot = await userRef.get();
|
||||
|
||||
if (userSnapshot.exists) {
|
||||
await userRef.update({'imgEspecializaciones': photoPaths});
|
||||
await userRef.update({'imgEspecializaciones': filePaths});
|
||||
|
||||
print('¡Imágenes de especializaciones actualizadas correctamente!');
|
||||
} else {
|
||||
await userRef.set({'imgEspecializaciones': photoPaths});
|
||||
await userRef.set({'imgEspecializaciones': filePaths});
|
||||
print('¡Imágenes de especializaciones agregadas correctamente!');
|
||||
}
|
||||
|
||||
print('Archivos de especializaciones actualizados correctamente');
|
||||
} catch (e) {
|
||||
print(
|
||||
'Error al agregar o actualizar las imágenes de especializaciones: $e');
|
||||
print('Error al actualizar los archivos de especializaciones: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user