From 352bb40145b55811a1c0d082c207fbd8a95c1188 Mon Sep 17 00:00:00 2001 From: Juan Felipe Duarte <70235683+DuarteJFelipe@users.noreply.github.com> Date: Mon, 26 Jun 2023 17:38:13 -0500 Subject: [PATCH] update --- lib/src/screens/horario.dart | 23 ++---- lib/src/screens/login_email.dart | 5 +- lib/src/screens/professional.dart | 7 +- lib/src/screens/profile_pro.dart | 96 ++++++++++++++++++++--- lib/src/screens/profile_pro_web.dart | 110 +++++++++++++++++++++------ lib/src/screens/profile_web.dart | 11 +++ lib/src/screens/register.dart | 5 +- 7 files changed, 197 insertions(+), 60 deletions(-) diff --git a/lib/src/screens/horario.dart b/lib/src/screens/horario.dart index c982425..7770304 100644 --- a/lib/src/screens/horario.dart +++ b/lib/src/screens/horario.dart @@ -5,24 +5,11 @@ import 'package:prosappco/src/components/pop_appbar.dart'; import 'package:prosappco/src/components/primary_btn.dart'; import '../components/schedule_picker.dart'; -class HorarioScreen extends StatefulWidget { +class HorarioScreen extends StatelessWidget { Map horarios; HorarioScreen({super.key, required this.horarios}); - @override - State createState() => _HorarioScreenState(); -} - -class _HorarioScreenState extends State { final uid = AuthenticationRepository.instance.getCurrentUserUid(); - - @override - void initState() { - super.initState(); - - print('horario a ${widget.horarios}'); - } - bool lunesValue = false; bool martesValue = false; bool miercolesValue = false; @@ -32,10 +19,10 @@ class _HorarioScreenState extends State { bool domingoValue = false; bool jornadaContinuaLunes = false; - Future updateHorario() async { + Future updateHorario(BuildContext context) async { try { Map horariosMap = {}; - widget.horarios.forEach((key, value) { + horarios.forEach((key, value) { horariosMap[key] = { 'habilitado': value.habilitado, 'jornadaContinua': value.jornadaContinua, @@ -87,7 +74,7 @@ class _HorarioScreenState extends State { @override Widget build(BuildContext context) { final sortedHorarios = Map.fromEntries( - widget.horarios.entries.toList() + horarios.entries.toList() ..sort( (a, b) => _dayOfWeekToInt(a.key).compareTo(_dayOfWeekToInt(b.key))), ); @@ -118,7 +105,7 @@ class _HorarioScreenState extends State { padding: const EdgeInsets.only(top: 30, bottom: 30), child: PrimaryButtom( onPressed: () async { - await updateHorario(); + await updateHorario(context); Navigator.pop(context); }, label: 'Guardar', diff --git a/lib/src/screens/login_email.dart b/lib/src/screens/login_email.dart index 8f478a2..d6048cd 100644 --- a/lib/src/screens/login_email.dart +++ b/lib/src/screens/login_email.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get/get.dart'; @@ -93,7 +94,7 @@ class _LoginEmailScreenState extends State { margin: const EdgeInsets.only(top: 210, left: 50, right: 50), child: Column( children: [ - !isIOS + !isIOS && !kIsWeb ? Padding( padding: const EdgeInsets.only(bottom: 20), child: ElevatedButton( @@ -126,7 +127,7 @@ class _LoginEmailScreenState extends State { )), ) : const SizedBox(), - !isIOS + !isIOS && !kIsWeb ? const Padding( padding: EdgeInsets.symmetric(vertical: 5), child: Row( diff --git a/lib/src/screens/professional.dart b/lib/src/screens/professional.dart index 3d72f1a..f263870 100644 --- a/lib/src/screens/professional.dart +++ b/lib/src/screens/professional.dart @@ -10,7 +10,6 @@ import 'package:prosappco/src/components/pop_appbar.dart'; import 'package:prosappco/src/models/setting_model.dart'; import 'package:prosappco/src/models/user_model.dart'; import 'package:prosappco/src/screens/professional_info.dart'; - import '../models/scores_model.dart'; class ProfessionalScreen extends StatefulWidget { @@ -227,10 +226,8 @@ class _ProfessionalScreenState extends State { try { QuerySnapshot users = await usersCollection.get(); for (DocumentSnapshot user in users.docs) { - // Acceder a los datos de cada usuario Map data = user.data() as Map; - // Crear un objeto Professional a partir de los datos del usuario _photo = await AuthenticationRepository.instance.getPhoto(user.id); if (data['estado'] == 'activo') { @@ -242,7 +239,9 @@ class _ProfessionalScreenState extends State { .toList(); if (widget.profession == data['profesion'] || - widget.profession == '' && userme?.city == data['city']) { + widget.profession == '' && + userme?.city == data['city'] && + data['ubicacion'] != null) { Professional professional = Professional( id: user.id, name: data['name'], diff --git a/lib/src/screens/profile_pro.dart b/lib/src/screens/profile_pro.dart index 10608fd..e752463 100644 --- a/lib/src/screens/profile_pro.dart +++ b/lib/src/screens/profile_pro.dart @@ -131,6 +131,91 @@ class _ProfileProScreenState extends State { } } + void createSchedules() async { + if (_horarios == null || _horarios!.isEmpty) { + final defaultSchedule = { + 'Lunes': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + }, + 'Martes': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + }, + 'Miercoles': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + }, + 'Jueves': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + }, + 'Viernes': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + }, + 'Sabado': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + }, + 'Domingo': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + } + }; + + try { + await FirebaseFirestore.instance + .collection('users') + .doc(uid) + .update({'horario': defaultSchedule}); + + Navigator.pop(context); + } catch (e) { + print(e); + } + } else { + Navigator.pushReplacement( + context, + CupertinoPageRoute( + builder: (BuildContext context) { + return HorarioScreen( + horarios: _horarios!, + ); + }, + ), + ); + } + } + Future updateInfo() async { if (_opcionalAddressController.text.isNotEmpty) { FirebaseFirestore.instance @@ -445,16 +530,7 @@ class _ProfileProScreenState extends State { ), GestureDetector( onTap: () { - Navigator.pushReplacement( - context, - CupertinoPageRoute( - builder: (BuildContext context) { - return HorarioScreen( - horarios: _horarios!, - ); - }, - ), - ); + createSchedules(); }, child: Padding( padding: const EdgeInsets.symmetric(vertical: 10), diff --git a/lib/src/screens/profile_pro_web.dart b/lib/src/screens/profile_pro_web.dart index ff64bf7..20e9ccf 100644 --- a/lib/src/screens/profile_pro_web.dart +++ b/lib/src/screens/profile_pro_web.dart @@ -186,19 +186,6 @@ class _ProfileProWebScreenState extends State { return; } - void name() { - _horarios!.forEach((dia, horario) { - print('Día: $dia'); - print('Habilitado: ${horario.habilitado}'); - print('Jornada Continua: ${horario.jornadaContinua}'); - print('Rango 1 Hora 1: ${horario.range1Hour1}'); - print('Rango 1 Hora 2: ${horario.range1Hour2}'); - print('Rango 2 Hora 1: ${horario.range2Hour1}'); - print('Rango 2 Hora 2: ${horario.range2Hour2}'); - print('-----------------------------------'); - }); - } - Future updateImage(image) async { try { await FirebaseFirestore.instance @@ -221,6 +208,91 @@ class _ProfileProWebScreenState extends State { } } + void createSchedules() async { + if (_horarios == null || _horarios!.isEmpty) { + final defaultSchedule = { + 'Lunes': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + }, + 'Martes': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + }, + 'Miercoles': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + }, + 'Jueves': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + }, + 'Viernes': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + }, + 'Sabado': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + }, + 'Domingo': { + 'habilitado': false, + 'jornadaContinua': false, + 'range1Hour1': null, + 'range1Hour2': null, + 'range2Hour1': null, + 'range2Hour2': null + } + }; + + try { + await FirebaseFirestore.instance + .collection('users') + .doc(uid) + .update({'horario': defaultSchedule}); + + Navigator.pop(context); + } catch (e) { + print(e); + } + } else { + Navigator.pushReplacement( + context, + CupertinoPageRoute( + builder: (BuildContext context) { + return HorarioScreen( + horarios: _horarios!, + ); + }, + ), + ); + } + } + Future uploadImage(File image) async { final String namefile = image.path.split('/').last; @@ -376,16 +448,7 @@ class _ProfileProWebScreenState extends State { ), GestureDetector( onTap: () { - Navigator.pushReplacement( - context, - CupertinoPageRoute( - builder: (BuildContext context) { - return HorarioScreen( - horarios: _horarios!, - ); - }, - ), - ); + createSchedules(); }, child: Padding( padding: const EdgeInsets.symmetric(vertical: 10), @@ -517,7 +580,6 @@ class _ProfileProWebScreenState extends State { PrimaryButtom( onPressed: () { updateInfo(); - // name(); }, label: 'Guardar'), const SizedBox( diff --git a/lib/src/screens/profile_web.dart b/lib/src/screens/profile_web.dart index c278844..927e7a5 100644 --- a/lib/src/screens/profile_web.dart +++ b/lib/src/screens/profile_web.dart @@ -145,6 +145,17 @@ class _ProfileWebScreenState extends State { snackPosition: SnackPosition.BOTTOM, ); return; + } else { + try { + await FirebaseAuth.instance.currentUser!.updateDisplayName(newName); + await FirebaseFirestore.instance.collection('users').doc(uid).update({ + 'name': newName, + 'lowerName': newName.toLowerCase(), + }); + print('Nombre actualizado correctamente'); + } catch (e) { + print('Error al actualizar el nombre: $e'); + } } if (newEmail.isEmpty) { // Si el nuevo nombre está vacío, no lo actualizamos y mostramos un mensaje al usuario diff --git a/lib/src/screens/register.dart b/lib/src/screens/register.dart index c2c86ae..deb2158 100644 --- a/lib/src/screens/register.dart +++ b/lib/src/screens/register.dart @@ -1,4 +1,5 @@ import 'package:firebase_auth/firebase_auth.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get/get.dart'; @@ -96,7 +97,7 @@ class _RegisterScreenState extends State { margin: const EdgeInsets.only(top: 200, left: 50, right: 50), child: Column( children: [ - !isIOS + !isIOS && !kIsWeb ? Padding( padding: const EdgeInsets.only(bottom: 20), child: ElevatedButton( @@ -129,7 +130,7 @@ class _RegisterScreenState extends State { )), ) : const SizedBox(), - !isIOS + !isIOS && !kIsWeb ? const Padding( padding: EdgeInsets.symmetric(vertical: 0), child: Row(