From aaa249d6f5425485c5ddef55fb3d7792a451c014 Mon Sep 17 00:00:00 2001 From: Juan Felipe Duarte <70235683+DuarteJFelipe@users.noreply.github.com> Date: Mon, 24 Apr 2023 09:15:58 -0500 Subject: [PATCH] perfil profesional terminado --- .../authentication_repository.dart | 26 ++++++ lib/src/screens/horario.dart | 30 ++++++- lib/src/screens/profile_pro.dart | 81 ++++++++++++++++++- 3 files changed, 133 insertions(+), 4 deletions(-) diff --git a/lib/src/authentication/authentication_repository.dart b/lib/src/authentication/authentication_repository.dart index 38b11bb..421d9ae 100644 --- a/lib/src/authentication/authentication_repository.dart +++ b/lib/src/authentication/authentication_repository.dart @@ -175,6 +175,32 @@ class AuthenticationRepository extends GetxController { return address; } + Future getUbicacion(String uid) async { + String location = ''; + try { + final snapshot = + await FirebaseFirestore.instance.collection('users').doc(uid).get(); + final Map? data = snapshot.data(); + location = data?['ubicacion'] ?? ''; + } catch (e) { + print('Error getting address: $e'); + } + return location; + } + + Future getOpcionalAddress(String uid) async { + String opcional_location = ''; + try { + final snapshot = + await FirebaseFirestore.instance.collection('users').doc(uid).get(); + final Map? data = snapshot.data(); + opcional_location = data?['opcional_address'] ?? ''; + } catch (e) { + print('Error getting address: $e'); + } + return opcional_location; + } + Future getPhoto(String uid) async { String photo = ''; try { diff --git a/lib/src/screens/horario.dart b/lib/src/screens/horario.dart index 012495c..ddc1efa 100644 --- a/lib/src/screens/horario.dart +++ b/lib/src/screens/horario.dart @@ -63,8 +63,34 @@ class _HorarioScreenState extends State { } } + int _dayOfWeekToInt(String dayOfWeek) { + switch (dayOfWeek) { + case 'Lunes': + return 1; + case 'Martes': + return 2; + case 'Miercoles': + return 3; + case 'Jueves': + return 4; + case 'Viernes': + return 5; + case 'Sabado': + return 6; + case 'Domingo': + return 7; + default: + throw ArgumentError('Invalid day of week: $dayOfWeek'); + } + } + @override Widget build(BuildContext context) { + final sortedHorarios = Map.fromEntries( + widget.horarios.entries.toList() + ..sort( + (a, b) => _dayOfWeekToInt(a.key).compareTo(_dayOfWeekToInt(b.key))), + ); return SafeArea( child: Scaffold( appBar: PopAppbar( @@ -82,7 +108,7 @@ class _HorarioScreenState extends State { height: 5, ), Column( - children: widget.horarios.entries.map( + children: sortedHorarios.entries.map( (entry) { return SchedulePicker( name: entry.key, @@ -92,7 +118,7 @@ class _HorarioScreenState extends State { ).toList(), ), Padding( - padding: const EdgeInsets.only(top: 100, bottom: 30), + padding: const EdgeInsets.only(top: 30, bottom: 30), child: PrimaryButtom( onPressed: () async { updateHorario().then((value) => Navigator.pushReplacement( diff --git a/lib/src/screens/profile_pro.dart b/lib/src/screens/profile_pro.dart index 212ef38..9abca40 100644 --- a/lib/src/screens/profile_pro.dart +++ b/lib/src/screens/profile_pro.dart @@ -6,6 +6,7 @@ import 'package:firebase_storage/firebase_storage.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_animate/flutter_animate.dart'; +import 'package:get/get.dart'; import 'package:prosappco/src/authentication/authentication_repository.dart'; import 'package:prosappco/src/components/banner_photo.dart'; import 'package:prosappco/src/components/drawer_professional.dart'; @@ -25,6 +26,8 @@ class ProfilePro extends StatefulWidget { class _ProfileProState extends State { final uid = AuthenticationRepository.instance.getCurrentUserUid(); + final TextEditingController _opcionalAddressController = + TextEditingController(); File? image_portada; File? imagen_to_upload; @@ -35,6 +38,8 @@ class _ProfileProState extends State { var _photo = '...'; var _direccion = '...'; + var _ubicacion = '...'; + var _opcionalAddress = '...'; Map? _horarios; @@ -71,12 +76,77 @@ class _ProfileProState extends State { _direccion = s; })); } + if (_ubicacion == '...') { + AuthenticationRepository.instance.getUbicacion(uid.toString()).then( + (String s) => setState( + () { + _ubicacion = s; + if (_ubicacion == 'ambos') { + sitioValue = true; + domicilioValue = true; + } else if (_ubicacion == 'sitio') { + sitioValue = true; + } else if (_ubicacion == 'domicilio') { + domicilioValue = true; + } + }, + ), + ); + } + if (_opcionalAddress == '...') { + AuthenticationRepository.instance.getOpcionalAddress(uid.toString()).then( + (String s) => setState( + () { + _opcionalAddress = s; + + if (_opcionalAddress != '...') { + _opcionalAddressController.text = _opcionalAddress; + } + }, + ), + ); + } } Future updateInfo() async { + if (_opcionalAddressController.text.isNotEmpty) { + FirebaseFirestore.instance + .collection('users') + .doc(uid) + .update({'opcional_address': _opcionalAddressController.text}); + } + + if (domicilioValue && sitioValue) { + FirebaseFirestore.instance + .collection('users') + .doc(uid) + .update({'ubicacion': 'ambos'}); + } else if (domicilioValue) { + FirebaseFirestore.instance + .collection('users') + .doc(uid) + .update({'ubicacion': 'domicilio'}); + } else if (sitioValue) { + FirebaseFirestore.instance + .collection('users') + .doc(uid) + .update({'ubicacion': 'sitio'}); + } else { + Get.snackbar( + 'Elige como vas a dar tu servicio', + 'Selecciona si tu servicio es a domicilio o en tu consultorio.', + snackPosition: SnackPosition.TOP, + backgroundColor: Colors.black.withOpacity(0.2), + messageText: const Text( + 'Selecciona si tu servicio es a domicilio o en tu consultorio.', + style: TextStyle(color: Colors.white), + ), + ); + return; + } + try { if (imagen_to_upload == null) { - return; } else { final uploaded = await uploadImage(imagen_to_upload!); updateImage(photoTemp); @@ -85,6 +155,13 @@ class _ProfileProState extends State { } catch (e) { print('Error al actualizar la imagen de perfil $e'); } + + Get.snackbar( + 'Información actualizada', + 'Su información a sido actualizada con exito.', + snackPosition: SnackPosition.TOP, + ); + return; } Future updateImage(image) async { @@ -269,7 +346,7 @@ class _ProfileProState extends State { ), const SizedBox(height: 10), TextFormField( - // controller: _emailController, + controller: _opcionalAddressController, decoration: const InputDecoration( hintText: 'Oficina / Piso / Conjunto'), ),