From 7977a9be2488f51479fab5527c9ea65e2ec5fe3e Mon Sep 17 00:00:00 2001 From: Felipe Date: Sat, 6 Jan 2024 13:59:44 -0500 Subject: [PATCH] update --- lib/src/components/photo_view_web.dart | 2 +- lib/src/models/professional_model.dart | 14 +- .../presentation/screens/calendar_pro.dart | 23 +-- lib/src/presentation/screens/map/service.dart | 149 ++++++------------ .../presentation/screens/professional.dart | 17 +- 5 files changed, 72 insertions(+), 133 deletions(-) diff --git a/lib/src/components/photo_view_web.dart b/lib/src/components/photo_view_web.dart index b814c91..77a0957 100644 --- a/lib/src/components/photo_view_web.dart +++ b/lib/src/components/photo_view_web.dart @@ -92,7 +92,7 @@ class DefaultPhotoWeb extends StatelessWidget { color: const Color.fromARGB(255, 255, 255, 255), size: iconDefault, ), - ).animate().shake(); + ); } } diff --git a/lib/src/models/professional_model.dart b/lib/src/models/professional_model.dart index 2360791..7a9f483 100644 --- a/lib/src/models/professional_model.dart +++ b/lib/src/models/professional_model.dart @@ -40,19 +40,7 @@ class Professional { @override String toString() { - return 'Professional {\n' - ' professionalRef: $professionalRef,\n' - ' name: $name,\n' - ' professionName: $professionName,\n' - ' cityName: $cityName,\n' - ' ubicacion: $ubicacion,\n' - ' realAddress: $realAddress,\n' - ' latitude: $latitude,\n' - ' longitude: $longitude,\n' - ' professionalEspecializado: ${getEspecializaciones()}\n' - ' tarifa: $tarifa,\n' - ' token: $token,\n' - '}'; + return 'Professional { professionalRef: $professionalRef, name: $name, professionName: $professionName, cityName: $cityName, ubicacion: $ubicacion, realAddress: $realAddress, latitude: $latitude, longitude: $longitude, professionalEspecializado: ${getEspecializaciones()} tarifa: $tarifa token: $token, }'; } static Future getProfessional(String uid) async { diff --git a/lib/src/presentation/screens/calendar_pro.dart b/lib/src/presentation/screens/calendar_pro.dart index 41f5baa..e1420d6 100644 --- a/lib/src/presentation/screens/calendar_pro.dart +++ b/lib/src/presentation/screens/calendar_pro.dart @@ -101,7 +101,7 @@ class _CalendarProScreenState extends State { color: const Color.fromARGB(255, 224, 247, 255), child: TableCalendar( locale: 'es_MX', - firstDay: DateTime.utc(2010, 10, 16), + firstDay: DateTime.now(), lastDay: lastDay, focusedDay: today, availableGestures: AvailableGestures.all, @@ -213,14 +213,19 @@ class _CalendarProScreenState extends State { ), child: ListTile( onTap: () { - Navigator.pushAndRemoveUntil( - context, - MaterialPageRoute( - builder: (context) => ServiceScreen( - fechaSeleccionada: today, horaSeleccionada: time), - ), - (route) => false, // Elimina todas las rutas en la pila - ); + Navigator.pop(context, [today, time, widget.professional]); + + // Navigator.pushAndRemoveUntil( + // context, + // MaterialPageRoute( + // builder: (context) => ServiceScreen( + // fechaSeleccionada: today, + // horaSeleccionada: time, + // professionalSeleccionado: widget.professional, + // ), + // ), + // (route) => false, + // ); }, contentPadding: const EdgeInsets.all(16), leading: Container( diff --git a/lib/src/presentation/screens/map/service.dart b/lib/src/presentation/screens/map/service.dart index b62d294..9b821a5 100644 --- a/lib/src/presentation/screens/map/service.dart +++ b/lib/src/presentation/screens/map/service.dart @@ -29,15 +29,14 @@ import 'package:prosappco/src/presentation/widgets/shared/drawer_menu.dart'; import 'package:prosappco/src/presentation/widgets/shared/primary_button.dart'; import 'package:prosappco/src/presentation/widgets/shared/warning_snackbar.dart'; import 'package:prosappco/src/providers/user_provider.dart'; +import 'package:prosappco/src/utils/time_of_day_extension.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; class ServiceScreen extends StatefulWidget { - final DateTime? fechaSeleccionada; - final TimeOfDay? horaSeleccionada; - - const ServiceScreen( - {super.key, this.fechaSeleccionada, this.horaSeleccionada}); + const ServiceScreen({ + super.key, + }); @override State createState() => _ServiceScreenState(); @@ -95,6 +94,10 @@ class _ServiceScreenState extends State { late final FirebaseAuth _auth; final _nameController = TextEditingController(); + DateTime? fechaSeleccionada; + TimeOfDay? horaSeleccionada; + Professional? profesionalSeleccionado; + @override void initState() { super.initState(); @@ -105,9 +108,6 @@ class _ServiceScreenState extends State { _auth = FirebaseAuth.instance; - print('jurgo 1 ${widget.fechaSeleccionada}'); - print('jurgo 2 ${widget.horaSeleccionada}'); - final currentUser = _auth.currentUser; if (currentUser != null && currentUser.displayName != null) { @@ -507,11 +507,15 @@ class _ServiceScreenState extends State { }, ), ); + if (datos != null) { - Professional? profesional = datos[0]; - ubicacion = datos[1]; + fechaSeleccionada = datos[0]; + horaSeleccionada = datos[1]; + Professional? profesional = datos[2]; + profesionalSeleccionado = profesional; if (profesional != null) { + ubicacion = profesional.ubicacion; if (mounted) { setState(() { _profesionalController.text = @@ -619,12 +623,10 @@ class _ServiceScreenState extends State { }, ), ), - widget.fechaSeleccionada == null && - widget.horaSeleccionada == null + fechaSeleccionada == null && horaSeleccionada == null ? const SizedBox() : const SizedBox(height: 15), - widget.fechaSeleccionada == null && - widget.horaSeleccionada == null + fechaSeleccionada == null && horaSeleccionada == null ? const SizedBox() : Row( children: [ @@ -635,71 +637,40 @@ class _ServiceScreenState extends State { prefixIcon: Icon(Icons.calendar_month), hintText: 'Fecha', ), - // controller: TextEditingController( - // text: _selectedDate == null - // ? '' - // : formatter.format(_selectedDate!), - // ), controller: TextEditingController( - text: widget.fechaSeleccionada == null + text: fechaSeleccionada == null ? '' - : formatter - .format(widget.fechaSeleccionada!), + : formatter.format(fechaSeleccionada!), ), - // onTap: () { - // if (_profesionalController - // .text.isNotEmpty) { - // _selectDateAndTime(context); - // } else { - // WarningSnackbar.show( - // title: 'Selecciona un profesional', - // message: - // 'Selecciona un profesional antes de elegir la fecha y la hora de la cita.', - // backgroundColor: Colors.orange, - // ); - // } - // }, ), ), Expanded( child: TextFormField( - // onTap: () { - // if (_profesionalController.text.isNotEmpty) { - // _selectDateAndTime(context); - // } else { - // WarningSnackbar.show( - // title: 'Selecciona un profesional', - // message: - // 'Selecciona un profesional antes de elegir la fecha y la hora de la cita.', - // backgroundColor: Colors.orange); - // } - // }, readOnly: true, decoration: const InputDecoration( prefixIcon: Icon(Icons.watch_later_outlined), hintText: 'Hora', ), - // controller: TextEditingController( - // text: _selectedTime == null - // ? '' - // : ' ${_selectedTime!.format(context)}', - // ), controller: TextEditingController( - text: widget.horaSeleccionada == null + text: horaSeleccionada == null ? '' - : ' ${widget.horaSeleccionada!.format(context)}', + : ' ${horaSeleccionada!.format(context)}', ), )) ], ), - const SizedBox(height: 15), - TextFormField( - controller: _observacionController, - decoration: const InputDecoration( - prefixIcon: Icon(Icons.message_outlined), - hintText: 'Observaciones', - ), - ), + fechaSeleccionada == null && horaSeleccionada == null + ? const SizedBox() + : const SizedBox(height: 15), + fechaSeleccionada == null && horaSeleccionada == null + ? const SizedBox() + : TextFormField( + controller: _observacionController, + decoration: const InputDecoration( + prefixIcon: Icon(Icons.message_outlined), + hintText: 'Observaciones', + ), + ), const SizedBox(height: 20), Center( child: PrimaryButton( @@ -724,25 +695,25 @@ class _ServiceScreenState extends State { ); } else { try { - final DateTime combinedDate = DateTime( - _selectedDate!.year, - _selectedDate!.month, - _selectedDate!.day, - _selectedTime!.hour, - _selectedTime!.minute, + DateTime time1 = DateTime( + fechaSeleccionada!.year, + fechaSeleccionada!.month, + fechaSeleccionada!.day, + horaSeleccionada!.hour, + horaSeleccionada!.minute, ); - DateTime time2 = combinedDate.add( - const Duration(hours: 2), - ); + DateTime time2 = + time1.add(const Duration(hours: 2)); UserModel.getUser(uid.toString()).then((value) { eventoService .createEvent( value.name, _observacionController.text, - '$_selectedDate', - '$combinedDate', + fechaSeleccionada.toString().substring(0, + fechaSeleccionada.toString().length - 1), + '$time1', '$time2', professionalId, ubicacion, @@ -780,7 +751,7 @@ class _ServiceScreenState extends State { WarningSnackbar.show( title: 'Llena todos los campos', message: - 'Asegurate de llenar todos los campos antes de solicitar un servicio.', + 'Asegurate de llenar todos los campos antes de solicitar un servicio. $e', ); } } @@ -995,38 +966,6 @@ class _ServiceScreenState extends State { } } - Future _selectDate(BuildContext context) async { - final DateTime? picked = await showDatePicker( - context: context, - initialDate: now, - firstDate: now, - lastDate: DateTime(now.year + 1), - ); - - if (picked != null && picked != _selectedDate) { - if (mounted) { - setState(() { - _selectedDate = picked; - }); - } - } - } - - Future _selectTime(BuildContext context) async { - final TimeOfDay? pickedTime = await showTimePicker( - context: context, - initialTime: TimeOfDay.now(), - ); - - if (pickedTime != null) { - if (mounted) { - setState(() { - _selectedTime = pickedTime; - }); - } - } - } - Future>>> getUsersWithActiveStatus( String serviceType) async { dynamic querySnapshot; diff --git a/lib/src/presentation/screens/professional.dart b/lib/src/presentation/screens/professional.dart index 5387768..caab246 100644 --- a/lib/src/presentation/screens/professional.dart +++ b/lib/src/presentation/screens/professional.dart @@ -17,7 +17,10 @@ import '../../models/scores_model.dart'; class ProfessionalScreen extends StatefulWidget { final String profession; - const ProfessionalScreen({super.key, required this.profession}); + const ProfessionalScreen({ + super.key, + required this.profession, + }); @override State createState() => _ProfessionalScreenState(); @@ -377,7 +380,7 @@ class _ProfessionalScreenState extends State { ), ], ), - onTap: () { + onTap: () async { if (professionals[index].ubicacion == 'ambos') { _showChoiceDialog(context).then((String? value) { if (value != null) { @@ -388,15 +391,19 @@ class _ProfessionalScreenState extends State { } else if (professionals[index].ubicacion == 'sitio') { // Navigator.pop(context, [professionals[index], 'sitio']); - - Navigator.of(context).push( + var datos = await Navigator.of(context).push( CupertinoPageRoute( builder: (BuildContext context) { return CalendarProScreen( - professional: professionals[index]); + professional: professionals[index], + ); }, ), ); + + if (datos != null) { + Navigator.pop(context, datos); + } } else { Navigator.pop( context, [professionals[index], 'domicilio']);