mapa mas pequeño

This commit is contained in:
Felipe
2023-09-01 19:11:46 -05:00
parent 0d1a06bcf9
commit 3a6db40866
+467 -457
View File
@@ -599,486 +599,496 @@ class _ServiceScreenState extends State<ServiceScreen> {
child: Scaffold( child: Scaffold(
backgroundColor: const Color(0xFFD6F4FF), backgroundColor: const Color(0xFFD6F4FF),
drawer: DrawerMenu(), drawer: DrawerMenu(),
body: SingleChildScrollView( body: Column(
reverse: true, children: [
child: Column( Stack(
children: [ children: [
Stack( SizedBox(
children: [ height: MediaQuery.of(context).size.height * 0.5,
SizedBox( child: GoogleMap(
height: MediaQuery.of(context).size.height * 0.6, mapType: MapType.normal,
child: GoogleMap( initialCameraPosition: initialCameraPosition,
mapType: MapType.normal, markers: markers,
initialCameraPosition: initialCameraPosition, zoomControlsEnabled: false,
markers: markers, onMapCreated: (GoogleMapController controller) {
zoomControlsEnabled: false, googleMapController = controller;
onMapCreated: (GoogleMapController controller) { },
googleMapController = controller; onCameraIdle: () {
}, if (professionalAddress == '') {
onCameraIdle: () { if (coordinates != null) {
if (professionalAddress == '') { getLocationName(
if (coordinates != null) { coordinates.latitude, coordinates.longitude)
getLocationName( .then((locationName) {
coordinates.latitude, coordinates.longitude) setState(() {
.then((locationName) { _locationController.text = locationName;
setState(() {
_locationController.text = locationName;
});
}); });
} });
} }
}, }
onCameraMove: (position) { },
setState(() { onCameraMove: (position) {
coordinates = position.target; setState(() {
}); coordinates = position.target;
}, });
gestureRecognizers: <Factory< },
OneSequenceGestureRecognizer>>{ gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{
Factory<OneSequenceGestureRecognizer>( Factory<OneSequenceGestureRecognizer>(
() => EagerGestureRecognizer(), () => 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,
), ),
), },
), ),
Padding( ),
padding: const EdgeInsets.all(20.0), const Positioned(
child: Builder( bottom: 25,
builder: (BuildContext context) { right: 0,
return ElevatedButton( left: 0,
style: ElevatedButton.styleFrom( top: 0,
backgroundColor: Colors.white, child: Icon(
shape: const CircleBorder(), Icons.location_on,
elevation: 3, size: 40,
minimumSize: const Size(50, 50), 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,
), ),
), ),
], ),
), Padding(
Container( padding: const EdgeInsets.all(20.0),
width: double.infinity, child: Builder(
decoration: const BoxDecoration(color: Colors.white), builder: (BuildContext context) {
child: Column( return ElevatedButton(
children: [ style: ElevatedButton.styleFrom(
const SizedBox(height: 5), backgroundColor: Colors.white,
SizedBox( shape: const CircleBorder(),
width: 320, elevation: 3,
child: Form( minimumSize: const Size(50, 50),
child: Column( ),
children: [ child: const Icon(
TextFormField( Icons.menu,
controller: _serviceTypeController, color: Colors.black,
readOnly: true, size: 30,
onTap: () async { ),
final String? serviceType = onPressed: () {
await Navigator.push( Scaffold.of(context).openDrawer();
context, },
CupertinoPageRoute( );
builder: (BuildContext context) { },
return const ServiceTypeScreen(); ),
}, ),
), ],
) as String?; ),
Expanded(
if (serviceType != null) { child: SingleChildScrollView(
setState(() { child: Container(
_serviceType = serviceType; width: double.infinity,
_serviceTypeController.text = _serviceType; height: MediaQuery.of(context).size.height * 0.5,
}); decoration: const BoxDecoration(color: Colors.white),
} child: Column(
}, children: [
decoration: const InputDecoration( SizedBox(
prefixIcon: Icon(Icons.room_service_rounded), width: 320,
suffixIcon: Icon(Icons.arrow_drop_down), child: Form(
hintText: 'Tipo de Servicio'), child: Column(
), children: [
const SizedBox(height: 15), TextFormField(
Column( controller: _serviceTypeController,
children: [ readOnly: true,
TextFormField( onTap: () async {
controller: _profesionalController, final String? serviceType =
readOnly: true, await Navigator.push(
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(
context, context,
CupertinoPageRoute( CupertinoPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
return const ProfileScreen(); return const ServiceTypeScreen();
}, },
), ),
); ) as String?;
} else {
try {
final DateTime combinedDate = DateTime(
_selectedDate!.year,
_selectedDate!.month,
_selectedDate!.day,
_selectedTime!.hour,
_selectedTime!.minute);
DateTime time2 = combinedDate if (serviceType != null) {
.add(const Duration(hours: 2)); setState(() {
_serviceType = serviceType;
UserModel.getUser(uid.toString()) _serviceTypeController.text =
.then((value) { _serviceType;
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,
);
} }
} },
}, decoration: const InputDecoration(
style: ElevatedButton.styleFrom( prefixIcon:
backgroundColor: const Color(0xFF2BA4EC), Icon(Icons.room_service_rounded),
shape: RoundedRectangleBorder( suffixIcon: Icon(Icons.arrow_drop_down),
borderRadius: BorderRadius.circular(50), hintText: 'Tipo de Servicio'),
),
elevation: 0,
minimumSize: const Size(230, 50),
), ),
child: const Text( const SizedBox(height: 15),
'Solicitar servicio', Column(
style: TextStyle( children: [
color: Colors.white, TextFormField(
fontWeight: FontWeight.bold, controller: _profesionalController,
fontSize: 18, 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,
),
),
),
],
),
), ),
), ),
), ],
], ),
), ),
), ),
], ),
), ],
), ),
), ),
); );