especializaciones
This commit is contained in:
@@ -356,8 +356,6 @@ class ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
|
||||
}
|
||||
|
||||
Future<void> updateImagesEspecializaciones(List<String> photoPaths) async {
|
||||
print('abc $photoPaths');
|
||||
|
||||
try {
|
||||
final userRef = FirebaseFirestore.instance.collection('users').doc(uid);
|
||||
final userSnapshot = await userRef.get();
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||
import 'package:prosappco/src/components/photo_view_web.dart';
|
||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'dart:io';
|
||||
|
||||
class ProfessionalProfileWebScreen extends StatefulWidget {
|
||||
const ProfessionalProfileWebScreen({super.key});
|
||||
@@ -30,7 +31,9 @@ class _ProfessionalProfileWebScreenState
|
||||
String selectedImage = '';
|
||||
String selectedCedulaImage = '';
|
||||
String selectedCertificadoImage = '';
|
||||
|
||||
List selectedEspecializacionImages = [];
|
||||
List<Uint8List> imagesEspecializacionsBytes = [];
|
||||
|
||||
XFile? file;
|
||||
Uint8List? selectedImagInBytes;
|
||||
@@ -39,7 +42,7 @@ class _ProfessionalProfileWebScreenState
|
||||
XFile? image_certificado;
|
||||
Uint8List? imageCertificadoBytes;
|
||||
XFile? image_especializaciones;
|
||||
Uint8List? imageespEcializacionesBytes;
|
||||
Uint8List? imageEspecializacionesBytes;
|
||||
|
||||
// controllers
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
@@ -112,16 +115,43 @@ class _ProfessionalProfileWebScreenState
|
||||
_selectFilesEspecializaciones(bool imageFrom) async {
|
||||
FilePickerResult? fileResult =
|
||||
await FilePicker.platform.pickFiles(allowMultiple: true);
|
||||
try {
|
||||
if (fileResult != null) {
|
||||
List<Uint8List> selectedFileBytes = [];
|
||||
|
||||
if (fileResult != null) {
|
||||
setState(() {
|
||||
fileResult.files.forEach((element) {
|
||||
selectedEspecializacionImages.add(element.name);
|
||||
for (var file in fileResult.files) {
|
||||
Uint8List? bytes = file.bytes;
|
||||
if (bytes != null) {
|
||||
selectedFileBytes.add(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
setState(() {
|
||||
imagesEspecializacionsBytes = selectedFileBytes;
|
||||
});
|
||||
|
||||
print('array - $selectedEspecializacionImages');
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
print('ya no te $e');
|
||||
}
|
||||
|
||||
print(imagesEspecializacionsBytes);
|
||||
// if (fileResult != null) {
|
||||
// setState(() {
|
||||
// try {
|
||||
// imagesEspecializacionsBytes =
|
||||
// fileResult.files.map((e) => File(e.path!)).toList();
|
||||
// } catch (e) {
|
||||
// print('error zd $e');
|
||||
// }
|
||||
|
||||
// // fileResult.files.forEach((element) {
|
||||
// // selectedEspecializacionImages.add(element.name);
|
||||
// // imagesEspecializacionsBytes.add(element.bytes);
|
||||
// // });
|
||||
|
||||
// print('array - $imagesEspecializacionsBytes');
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
Future<void> sendInfo() async {
|
||||
@@ -130,6 +160,9 @@ class _ProfessionalProfileWebScreenState
|
||||
});
|
||||
|
||||
final String cedula = _cedulaController.text.trim();
|
||||
final String especializacion = _especializacionController.text.trim();
|
||||
final List<String> especializaciones =
|
||||
especializacion.split(',').map((e) => e.trim()).toList();
|
||||
|
||||
if (cedula.isEmpty) {
|
||||
showSnackBar('Cedula invalida', 'Ingrese una cedula válida');
|
||||
@@ -150,13 +183,42 @@ class _ProfessionalProfileWebScreenState
|
||||
await FirebaseFirestore.instance.collection('users').doc(uid).update({
|
||||
'cedula': cedula,
|
||||
'estado': 'revision',
|
||||
// 'especializaciones': especializaciones
|
||||
'especializaciones': especializaciones
|
||||
});
|
||||
|
||||
// Sube las imágenes al storage de Firebase
|
||||
await uploadCedula();
|
||||
await uploadCertificado();
|
||||
// uploadEspecializaciones(images_especializacion);
|
||||
List<String> uploadedPhotoPaths =
|
||||
await uploadEspecializaciones(imagesEspecializacionsBytes);
|
||||
|
||||
if (uploadedPhotoPaths.isNotEmpty) {
|
||||
// Las imágenes se cargaron correctamente
|
||||
// Actualiza las imágenes en Firestore
|
||||
await updateImagesEspecializaciones(uploadedPhotoPaths);
|
||||
|
||||
// Navega a la siguiente pantalla
|
||||
Navigator.pushReplacementNamed(context, '/solicitudEnviada');
|
||||
} else {
|
||||
// Ocurrió un error al cargar las imágenes
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Error'),
|
||||
content: const Text('Ocurrió un error al cargar las imágenes.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Aceptar'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Actualiza la imagen de perfil si hay cambios
|
||||
if (selectedImagInBytes != null) {
|
||||
@@ -270,6 +332,33 @@ class _ProfessionalProfileWebScreenState
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<String>> uploadEspecializaciones(List<Uint8List> images) async {
|
||||
List<String> photoPaths = [];
|
||||
|
||||
for (Uint8List imageBytes in images) {
|
||||
Reference ref = storage
|
||||
.ref()
|
||||
.child('users')
|
||||
.child(uid!)
|
||||
.child('especializaciones')
|
||||
.child('${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<void> updateImageCedula(image) async {
|
||||
try {
|
||||
final userRef = FirebaseFirestore.instance.collection('users').doc(uid);
|
||||
@@ -326,6 +415,24 @@ class _ProfessionalProfileWebScreenState
|
||||
}
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
void showSnackBar(String title, String message) {
|
||||
Get.snackbar(
|
||||
title,
|
||||
@@ -496,12 +603,6 @@ class _ProfessionalProfileWebScreenState
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
_selectFilesEspecializaciones(true);
|
||||
|
||||
// final images = await getImage(3);
|
||||
// setState(() {
|
||||
// images_especializacion =
|
||||
// images.map((e) => File(e!.path)).toList();
|
||||
// });
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFFD6F4FF),
|
||||
@@ -511,24 +612,24 @@ class _ProfessionalProfileWebScreenState
|
||||
elevation: 0,
|
||||
minimumSize: const Size(250, 50),
|
||||
),
|
||||
child: const Row(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
const Text(
|
||||
'Especialización',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF2BA4EC),
|
||||
fontSize: 17,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 15),
|
||||
// Icon(
|
||||
// images_especializacion.isEmpty
|
||||
// ? Icons.file_upload_outlined
|
||||
// : Icons.check,
|
||||
// color: const Color(0xFF2BA4EC),
|
||||
// size: 30,
|
||||
// ),
|
||||
const SizedBox(width: 15),
|
||||
Icon(
|
||||
imagesEspecializacionsBytes.isEmpty
|
||||
? Icons.file_upload_outlined
|
||||
: Icons.check,
|
||||
color: const Color(0xFF2BA4EC),
|
||||
size: 30,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user