From 3a6db40866204d47bb9f6a7abc5708e5f093b5bc Mon Sep 17 00:00:00 2001 From: Felipe Date: Fri, 1 Sep 2023 19:11:46 -0500 Subject: [PATCH] =?UTF-8?q?mapa=20mas=20peque=C3=B1o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/screens/service.dart | 924 ++++++++++++++++++----------------- 1 file changed, 467 insertions(+), 457 deletions(-) diff --git a/lib/src/screens/service.dart b/lib/src/screens/service.dart index 427c718..6adef7b 100644 --- a/lib/src/screens/service.dart +++ b/lib/src/screens/service.dart @@ -599,486 +599,496 @@ class _ServiceScreenState extends State { child: Scaffold( backgroundColor: const Color(0xFFD6F4FF), drawer: DrawerMenu(), - body: SingleChildScrollView( - reverse: true, - child: Column( - children: [ - Stack( - children: [ - SizedBox( - height: MediaQuery.of(context).size.height * 0.6, - child: GoogleMap( - mapType: MapType.normal, - initialCameraPosition: initialCameraPosition, - markers: markers, - zoomControlsEnabled: false, - onMapCreated: (GoogleMapController controller) { - googleMapController = controller; - }, - onCameraIdle: () { - if (professionalAddress == '') { - if (coordinates != null) { - getLocationName( - coordinates.latitude, coordinates.longitude) - .then((locationName) { - setState(() { - _locationController.text = locationName; - }); + body: Column( + children: [ + Stack( + children: [ + SizedBox( + height: MediaQuery.of(context).size.height * 0.5, + child: GoogleMap( + mapType: MapType.normal, + initialCameraPosition: initialCameraPosition, + markers: markers, + zoomControlsEnabled: false, + onMapCreated: (GoogleMapController controller) { + googleMapController = controller; + }, + onCameraIdle: () { + if (professionalAddress == '') { + if (coordinates != null) { + getLocationName( + coordinates.latitude, coordinates.longitude) + .then((locationName) { + setState(() { + _locationController.text = locationName; }); - } + }); } - }, - onCameraMove: (position) { - setState(() { - coordinates = position.target; - }); - }, - gestureRecognizers: >{ - Factory( - () => EagerGestureRecognizer(), - ), - }, - ), - ), - const Positioned( - bottom: 25, - right: 0, - left: 0, - top: 0, - child: Icon( - Icons.location_on, - size: 40, - color: Color(0xFFFF0000), - ), - ), - Positioned( - bottom: 10, - right: 20, - child: FloatingActionButton( - onPressed: () async { - try { - Position position = await _determinePosition(); - - googleMapController.animateCamera( - CameraUpdate.newCameraPosition( - CameraPosition( - target: LatLng( - position.latitude, - position.longitude, - ), - zoom: 17), - ), - ); - setState(() {}); - } catch (e) { - Get.snackbar( - 'ubicación desactivada', - 'Por favor activa la ubicacion de tu telefono.', - snackPosition: SnackPosition.TOP, - ); - } - - // markers.clear(); - }, - elevation: 0, - child: const Icon( - Icons.gps_fixed, - size: 30, + } + }, + onCameraMove: (position) { + setState(() { + coordinates = position.target; + }); + }, + gestureRecognizers: >{ + Factory( + () => EagerGestureRecognizer(), ), - ), + }, ), - Padding( - padding: const EdgeInsets.all(20.0), - child: Builder( - builder: (BuildContext context) { - return ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: Colors.white, - shape: const CircleBorder(), - elevation: 3, - minimumSize: const Size(50, 50), + ), + const Positioned( + bottom: 25, + right: 0, + left: 0, + top: 0, + child: Icon( + Icons.location_on, + size: 40, + color: Color(0xFFFF0000), + ), + ), + Positioned( + bottom: 10, + right: 20, + child: FloatingActionButton( + onPressed: () async { + try { + Position position = await _determinePosition(); + + googleMapController.animateCamera( + CameraUpdate.newCameraPosition( + CameraPosition( + target: LatLng( + position.latitude, + position.longitude, + ), + zoom: 17), ), - child: const Icon( - Icons.menu, - color: Colors.black, - size: 30, - ), - onPressed: () { - Scaffold.of(context).openDrawer(); - }, ); - }, + setState(() {}); + } catch (e) { + Get.snackbar( + 'ubicación desactivada', + 'Por favor activa la ubicacion de tu telefono.', + snackPosition: SnackPosition.TOP, + ); + } + + // markers.clear(); + }, + elevation: 0, + child: const Icon( + Icons.gps_fixed, + size: 30, ), ), - ], - ), - Container( - width: double.infinity, - decoration: const BoxDecoration(color: Colors.white), - child: Column( - children: [ - const SizedBox(height: 5), - SizedBox( - width: 320, - child: Form( - child: Column( - children: [ - TextFormField( - controller: _serviceTypeController, - readOnly: true, - onTap: () async { - final String? serviceType = - await Navigator.push( - context, - CupertinoPageRoute( - builder: (BuildContext context) { - return const ServiceTypeScreen(); - }, - ), - ) as String?; - - if (serviceType != null) { - setState(() { - _serviceType = serviceType; - _serviceTypeController.text = _serviceType; - }); - } - }, - decoration: const InputDecoration( - prefixIcon: Icon(Icons.room_service_rounded), - suffixIcon: Icon(Icons.arrow_drop_down), - hintText: 'Tipo de Servicio'), - ), - const SizedBox(height: 15), - Column( - children: [ - TextFormField( - controller: _profesionalController, - readOnly: true, - onTap: () async { - final dynamic datos = await Navigator.push( - context, - CupertinoPageRoute( - builder: (BuildContext context) { - return ProfessionalScreen( - profession: - _serviceTypeController.text, - ); - }, - ), - ); - if (datos != null) { - Professional? profesional = datos[0]; - ubicacion = datos[1]; - - if (profesional != null) { - setState(() { - _profesionalController.text = - profesional.name.toString(); - - professionalId = profesional.id; - - if (profesional.token != '') { - professionalToken = - profesional.token!; - } - - 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), - ), - ); - } - } - }); - } - } - }, - decoration: const InputDecoration( - prefixIcon: - Icon(Icons.assignment_ind_rounded), - suffixIcon: Icon(Icons.arrow_drop_down), - hintText: 'Seleccionar profesional'), - ), - ], - ), - const SizedBox(height: 15), - TextFormField( - controller: _locationController, - decoration: const InputDecoration( - prefixIcon: Icon(Icons.near_me), - hintText: 'Dirección', - ), - onChanged: (value) { - String modifiedValue = - value.replaceAll(' ', '_'); - placeAutoComplete(modifiedValue); - }, - ), - SizedBox( - height: _placesList.isNotEmpty - ? 200 - : 0, // Ajusta la altura según tus necesidades - child: ListView.builder( - itemCount: _placesList.length, - itemBuilder: (context, index) { - return ListTile( - onTap: () { - final selectedAddress = _placesList[index] - ['formatted_address']; - final selectedLatitude = - _placesList[index]['geometry'] - ['location']['lat']; - final selectedLongitude = - _placesList[index]['geometry'] - ['location']['lng']; - - _locationController.text = - selectedAddress; - - final newCoordinates = LatLng( - selectedLatitude, selectedLongitude); - googleMapController.animateCamera( - CameraUpdate.newLatLng(newCoordinates), - ); - - setState(() { - _placesList = []; - }); - }, - title: Text(_placesList[index] - ['formatted_address']), - ); - }, - ), - ), - const SizedBox(height: 15), - Row( - children: [ - SizedBox( - width: 180, - child: TextFormField( - onTap: () { - if (_profesionalController - .text.isNotEmpty) { - _selectDate(context); - } else { - final snackBar = SnackBar( - backgroundColor: Colors.blue, - content: const Text( - 'Selecciona un profesional', - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.bold, - ), - ), - elevation: 8.0, - shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.circular(10.0), - ), - ); - - ScaffoldMessenger.of(context) - .showSnackBar(snackBar); - } - }, - readOnly: true, - decoration: InputDecoration( - prefixIcon: - const Icon(Icons.calendar_month), - suffixIcon: _selectedDate == null - ? const Icon(Icons.arrow_drop_down) - : null, - hintText: 'Fecha', - ), - controller: TextEditingController( - text: _selectedDate == null - ? '' - : formatter.format(_selectedDate!)), - ), - ), - SizedBox( - width: 140, - child: TextFormField( - onTap: () { - if (_profesionalController - .text.isNotEmpty) { - _selectTime(context); - } else { - final snackBar = SnackBar( - backgroundColor: Colors.blue, - content: const Text( - 'Selecciona un profesional', - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.bold, - ), - ), - elevation: 8.0, - shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.circular(10.0), - ), - ); - - ScaffoldMessenger.of(context) - .showSnackBar(snackBar); - } - }, - readOnly: true, - decoration: const InputDecoration( - suffixIcon: Icon(Icons.arrow_drop_down), - hintText: 'Hora', - ), - controller: TextEditingController( - text: _selectedTime == null - ? '' - : ' ${_selectedTime!.format(context)}'), - ), - ), - ], - ), - const SizedBox(height: 15), - TextFormField( - controller: _observacionController, - decoration: const InputDecoration( - prefixIcon: Icon(Icons.message_outlined), - hintText: 'Observaciones'), - ), - const SizedBox(height: 20), - ElevatedButton( - onPressed: () { - if (user?.name == null || - user?.name == '' || - user?.phoneNumber == null || - user?.phoneNumber == '') { - Navigator.push( + ), + Padding( + padding: const EdgeInsets.all(20.0), + child: Builder( + builder: (BuildContext context) { + return ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Colors.white, + shape: const CircleBorder(), + elevation: 3, + minimumSize: const Size(50, 50), + ), + child: const Icon( + Icons.menu, + color: Colors.black, + size: 30, + ), + onPressed: () { + Scaffold.of(context).openDrawer(); + }, + ); + }, + ), + ), + ], + ), + Expanded( + child: SingleChildScrollView( + child: Container( + width: double.infinity, + height: MediaQuery.of(context).size.height * 0.5, + decoration: const BoxDecoration(color: Colors.white), + child: Column( + children: [ + SizedBox( + width: 320, + child: Form( + child: Column( + children: [ + TextFormField( + controller: _serviceTypeController, + readOnly: true, + onTap: () async { + final String? serviceType = + await Navigator.push( context, CupertinoPageRoute( builder: (BuildContext context) { - return const ProfileScreen(); + return const ServiceTypeScreen(); }, ), - ); - } else { - try { - final DateTime combinedDate = DateTime( - _selectedDate!.year, - _selectedDate!.month, - _selectedDate!.day, - _selectedTime!.hour, - _selectedTime!.minute); + ) as String?; - 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, - _locationController.text, - ubicacion != 'sitio' - ? coordinates.latitude - : professionalLatitude, - ubicacion != 'sitio' - ? coordinates.longitude - : professionalLongitude, - 'pendiente', - professionalTarifa == 0 - ? 0 - : professionalTarifa, - false, - false, - ) - .then((value) { - if (professionalToken != '') { - sendPushNotification( - professionalToken); - } - Navigator.pushReplacement( - context, - CupertinoPageRoute( - builder: (BuildContext context) { - return ServiceAfterScreen( - eventoId: value, - ); - }, - ), - ); - }); + if (serviceType != null) { + setState(() { + _serviceType = serviceType; + _serviceTypeController.text = + _serviceType; }); - } catch (e) { - Get.snackbar( - 'Llena todos los campos', - 'Asegurate de llenar todos los campos.', - snackPosition: SnackPosition.BOTTOM, - ); } - } - }, - style: ElevatedButton.styleFrom( - backgroundColor: const Color(0xFF2BA4EC), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(50), - ), - elevation: 0, - minimumSize: const Size(230, 50), + }, + decoration: const InputDecoration( + prefixIcon: + Icon(Icons.room_service_rounded), + suffixIcon: Icon(Icons.arrow_drop_down), + hintText: 'Tipo de Servicio'), ), - child: const Text( - 'Solicitar servicio', - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.bold, - fontSize: 18, + const SizedBox(height: 15), + Column( + children: [ + TextFormField( + controller: _profesionalController, + readOnly: true, + onTap: () async { + final dynamic datos = + await Navigator.push( + context, + CupertinoPageRoute( + builder: (BuildContext context) { + return ProfessionalScreen( + profession: + _serviceTypeController.text, + ); + }, + ), + ); + if (datos != null) { + Professional? profesional = datos[0]; + ubicacion = datos[1]; + + if (profesional != null) { + setState(() { + _profesionalController.text = + profesional.name.toString(); + + professionalId = profesional.id; + + if (profesional.token != '') { + professionalToken = + profesional.token!; + } + + 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), + ), + ); + } + } + }); + } + } + }, + decoration: const InputDecoration( + prefixIcon: + Icon(Icons.assignment_ind_rounded), + suffixIcon: Icon(Icons.arrow_drop_down), + hintText: 'Seleccionar profesional'), + ), + ], + ), + const SizedBox(height: 15), + TextFormField( + controller: _locationController, + decoration: const InputDecoration( + prefixIcon: Icon(Icons.near_me), + hintText: 'Dirección', + ), + onChanged: (value) { + String modifiedValue = + value.replaceAll(' ', '_'); + placeAutoComplete(modifiedValue); + }, + ), + SizedBox( + height: _placesList.isNotEmpty + ? 200 + : 0, // Ajusta la altura según tus necesidades + child: ListView.builder( + itemCount: _placesList.length, + itemBuilder: (context, index) { + return ListTile( + onTap: () { + final selectedAddress = + _placesList[index] + ['formatted_address']; + final selectedLatitude = + _placesList[index]['geometry'] + ['location']['lat']; + final selectedLongitude = + _placesList[index]['geometry'] + ['location']['lng']; + + _locationController.text = + selectedAddress; + + final newCoordinates = LatLng( + selectedLatitude, + selectedLongitude); + googleMapController.animateCamera( + CameraUpdate.newLatLng( + newCoordinates), + ); + + setState(() { + _placesList = []; + }); + }, + title: Text(_placesList[index] + ['formatted_address']), + ); + }, ), ), - ), - const SizedBox(height: 15), - ], + const SizedBox(height: 15), + Row( + children: [ + SizedBox( + width: 180, + child: TextFormField( + onTap: () { + if (_profesionalController + .text.isNotEmpty) { + _selectDate(context); + } else { + final snackBar = SnackBar( + backgroundColor: Colors.blue, + content: const Text( + 'Selecciona un profesional', + style: TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + ), + ), + elevation: 8.0, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(10.0), + ), + ); + + ScaffoldMessenger.of(context) + .showSnackBar(snackBar); + } + }, + readOnly: true, + decoration: InputDecoration( + prefixIcon: + const Icon(Icons.calendar_month), + suffixIcon: _selectedDate == null + ? const Icon(Icons.arrow_drop_down) + : null, + hintText: 'Fecha', + ), + controller: TextEditingController( + text: _selectedDate == null + ? '' + : formatter + .format(_selectedDate!)), + ), + ), + SizedBox( + width: 140, + child: TextFormField( + onTap: () { + if (_profesionalController + .text.isNotEmpty) { + _selectTime(context); + } else { + final snackBar = SnackBar( + backgroundColor: Colors.blue, + content: const Text( + 'Selecciona un profesional', + style: TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + ), + ), + elevation: 8.0, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(10.0), + ), + ); + + ScaffoldMessenger.of(context) + .showSnackBar(snackBar); + } + }, + readOnly: true, + decoration: const InputDecoration( + suffixIcon: Icon(Icons.arrow_drop_down), + hintText: 'Hora', + ), + controller: TextEditingController( + text: _selectedTime == null + ? '' + : ' ${_selectedTime!.format(context)}'), + ), + ), + ], + ), + const SizedBox(height: 15), + TextFormField( + controller: _observacionController, + decoration: const InputDecoration( + prefixIcon: Icon(Icons.message_outlined), + hintText: 'Observaciones'), + ), + const SizedBox(height: 20), + ElevatedButton( + onPressed: () { + 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, + _locationController.text, + ubicacion != 'sitio' + ? coordinates.latitude + : professionalLatitude, + ubicacion != 'sitio' + ? coordinates.longitude + : professionalLongitude, + 'pendiente', + professionalTarifa == 0 + ? 0 + : professionalTarifa, + false, + false, + ) + .then((value) { + if (professionalToken != '') { + sendPushNotification( + professionalToken); + } + 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), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(50), + ), + elevation: 0, + minimumSize: const Size(230, 50), + ), + child: const Text( + 'Solicitar servicio', + style: TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + fontSize: 18, + ), + ), + ), + ], + ), ), ), - ), - ], + ], + ), ), ), - ], - ), + ), + ], ), ), );