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