diff --git a/lib/src/screens/service.dart b/lib/src/screens/service.dart index 650304e..90c81c3 100644 --- a/lib/src/screens/service.dart +++ b/lib/src/screens/service.dart @@ -30,13 +30,13 @@ class ServiceScreen extends StatefulWidget { class _ServiceScreenState extends State { EventoService eventoService = EventoService(); - final TextEditingController _locationController = TextEditingController(); String _locationPosition = ''; String ubicacion = ''; - final _ubicationController = TextEditingController(); - final _profesionalController = TextEditingController(); - final _serviceTypeController = TextEditingController(); - final _observacionController = TextEditingController(); + final TextEditingController _locationController = TextEditingController(); + final TextEditingController _ubicationController = TextEditingController(); + final TextEditingController _profesionalController = TextEditingController(); + final TextEditingController _serviceTypeController = TextEditingController(); + final TextEditingController _observacionController = TextEditingController(); String professionalId = ''; int? professionalTarifa; String professionalAddress = ''; @@ -283,37 +283,15 @@ class _ServiceScreenState extends State { setState(() { _profesionalController.text = profesional.name.toString(); + professionalId = profesional.id; + professionalTarifa = profesional.tarifa ?? 0; + professionalUbicacion = profesional.ubicacion; + professionalAddress = _ubicationController.text; - // professionalId = profesional.id; - - // professionalTarifa = profesional.tarifa ?? 0; - - // professionalUbicacion = profesional.ubicacion; - - // professionalLatitude = profesional.latitude; - // professionalLongitude = profesional.longitude; - - // if (ubicacion == 'sitio') { - // professionalAddress = profesional.realAddress; - - // _locationController.text = profesional.realAddress; - - // if (professionalLatitude != null && - // professionalLatitude != 0 && - // professionalLongitude != null && - // professionalLongitude != 0) { - // googleMapController.animateCamera( - // CameraUpdate.newCameraPosition( - // CameraPosition( - // target: LatLng( - // professionalLatitude!, - // professionalLongitude!, - // ), - // zoom: 17), - // ), - // ); - // } - // } + if (ubicacion == 'sitio') { + professionalAddress = profesional.realAddress; + _ubicationController.text = profesional.realAddress; + } }); } } @@ -405,12 +383,70 @@ class _ServiceScreenState extends State { const SizedBox(height: 20.0), ElevatedButton( onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => LocalNotificationScreen(), - ), - ); + if (user?.name == null || + user?.name == '' || + user?.phoneNumber == null || + user?.phoneNumber == '') { + Navigator.push( + context, + CupertinoPageRoute( + builder: (BuildContext context) { + return const ProfileScreen(); + }, + ), + ); + } else { + try { + final DateTime combinedDate = DateTime( + _selectedDate!.year, + _selectedDate!.month, + _selectedDate!.day, + _selectedTime!.hour, + _selectedTime!.minute, + ); + + DateTime time2 = + combinedDate.add(const Duration(hours: 2)); + + UserModel.getUser(uid.toString()).then((value) { + eventoService + .createEvent( + value.name, + _observacionController.text, + '$_selectedDate', + '$combinedDate', + '$time2', + professionalId, + ubicacion, + professionalAddress, + 0.0, + 0.0, + 'pendiente', + professionalTarifa == 0 ? 0 : professionalTarifa, + false, + false, + ) + .then((value) { + Navigator.pushReplacement( + context, + CupertinoPageRoute( + builder: (BuildContext context) { + return ServiceAfterScreen( + eventoId: value, + ); + }, + ), + ); + }); + }); + } catch (e) { + Get.snackbar( + 'Llena todos los campos', + 'Asegurate de llenar todos los campos.', + snackPosition: SnackPosition.BOTTOM, + ); + } + } }, style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFF2BA4EC),