ubicacion
This commit is contained in:
+198
-143
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
import 'package:firebase_storage/firebase_storage.dart';
|
import 'package:firebase_storage/firebase_storage.dart';
|
||||||
@@ -22,6 +24,7 @@ import 'package:prosappco/src/screens/service_after.dart';
|
|||||||
import 'package:prosappco/src/screens/service_type.dart';
|
import 'package:prosappco/src/screens/service_type.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:prosappco/src/screens/ubicacion.dart';
|
||||||
|
|
||||||
class ServiceScreen extends StatefulWidget {
|
class ServiceScreen extends StatefulWidget {
|
||||||
const ServiceScreen({super.key});
|
const ServiceScreen({super.key});
|
||||||
@@ -35,6 +38,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
final TextEditingController _locationController = TextEditingController();
|
final TextEditingController _locationController = TextEditingController();
|
||||||
String _locationPosition = '';
|
String _locationPosition = '';
|
||||||
String ubicacion = '';
|
String ubicacion = '';
|
||||||
|
final _ubicationController = TextEditingController();
|
||||||
final _profesionalController = TextEditingController();
|
final _profesionalController = TextEditingController();
|
||||||
final _serviceTypeController = TextEditingController();
|
final _serviceTypeController = TextEditingController();
|
||||||
final _observacionController = TextEditingController();
|
final _observacionController = TextEditingController();
|
||||||
@@ -204,40 +208,6 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
void placeAutoComplete(String query) async {
|
|
||||||
String url = "https://admin.prosapp.co/autocomplete?input=$query";
|
|
||||||
|
|
||||||
Uri uri = Uri.parse(url);
|
|
||||||
|
|
||||||
// Imprimir la URL completa
|
|
||||||
print(uri.toString());
|
|
||||||
|
|
||||||
try {
|
|
||||||
http.Response response = await http.get(uri);
|
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
|
||||||
// Imprimir la respuesta
|
|
||||||
print(response.body);
|
|
||||||
} else {
|
|
||||||
// Manejar otros códigos de estado de respuesta
|
|
||||||
print("Error: ${response.statusCode}");
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Manejar errores de conexión o solicitud
|
|
||||||
print("Error: $error");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Uri uri = Uri.https("admin.prosapp.co", "/autocomplete", {
|
|
||||||
// "input": query,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// String? response = await NetworkUtility.fetchUrl(uri);
|
|
||||||
|
|
||||||
// if (response != null) {
|
|
||||||
// print(response);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (kIsWeb) {
|
if (kIsWeb) {
|
||||||
@@ -261,52 +231,203 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
'Prosapp',
|
'Prosapp',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
|
||||||
TextButton(
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return _EnterLocationDialog();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: const Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.location_on),
|
|
||||||
SizedBox(width: 8),
|
|
||||||
Text('Ingresar mi ubicación'),
|
|
||||||
SizedBox(width: 4),
|
|
||||||
Icon(Icons.keyboard_arrow_down_rounded, size: 16),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
), // Texto del título
|
), // Texto del título
|
||||||
),
|
),
|
||||||
body: Container(
|
body: Center(
|
||||||
child: ElevatedButton(
|
child: Container(
|
||||||
onPressed: () {
|
width: 300,
|
||||||
placeAutoComplete("Colombia");
|
child: Column(
|
||||||
},
|
children: [
|
||||||
style: ElevatedButton.styleFrom(
|
const SizedBox(height: 20.0),
|
||||||
backgroundColor: const Color(0xFF2BA4EC),
|
TextFormField(
|
||||||
shape: RoundedRectangleBorder(
|
controller: _ubicationController,
|
||||||
borderRadius: BorderRadius.circular(50),
|
readOnly: true,
|
||||||
),
|
onTap: () async {
|
||||||
elevation: 0,
|
final dynamic datos = await Navigator.push(
|
||||||
minimumSize: const Size(230, 50),
|
context,
|
||||||
),
|
CupertinoPageRoute(
|
||||||
child: const Text(
|
builder: (BuildContext context) {
|
||||||
'Aceptar',
|
return UbicacionScreen();
|
||||||
style: TextStyle(
|
},
|
||||||
color: Colors.white,
|
),
|
||||||
fontWeight: FontWeight.bold,
|
);
|
||||||
fontSize: 18,
|
print(datos);
|
||||||
),
|
if (datos != null) {
|
||||||
|
setState(() {
|
||||||
|
_ubicationController.text = datos;
|
||||||
|
print(_ubicationController.text);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: 'Escribe tu ubicación',
|
||||||
|
prefixIcon: Icon(Icons.location_on),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20.0),
|
||||||
|
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;
|
||||||
|
|
||||||
|
// 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: 20.0),
|
||||||
|
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!)),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20.0),
|
||||||
|
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(
|
||||||
|
prefixIcon: Icon(Icons.access_time),
|
||||||
|
suffixIcon: Icon(Icons.arrow_drop_down),
|
||||||
|
hintText: 'Hora',
|
||||||
|
),
|
||||||
|
controller: TextEditingController(
|
||||||
|
text: _selectedTime == null
|
||||||
|
? ''
|
||||||
|
: ' ${_selectedTime!.format(context)}'),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20.0),
|
||||||
|
TextFormField(
|
||||||
|
controller: _observacionController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
prefixIcon: Icon(Icons.message_outlined),
|
||||||
|
hintText: 'Observaciones'),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20.0),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {},
|
||||||
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -779,69 +900,3 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _EnterLocationDialog extends StatelessWidget {
|
|
||||||
const _EnterLocationDialog({super.key});
|
|
||||||
|
|
||||||
void placeAutoComplete(String query) async {
|
|
||||||
Uri uri =
|
|
||||||
Uri.https("maps.googleapis.com", "/maps/api/place/autocomplete/json", {
|
|
||||||
"input": query,
|
|
||||||
"key": apiKey,
|
|
||||||
});
|
|
||||||
|
|
||||||
String? response = await NetworkUtility.fetchUrl(uri);
|
|
||||||
|
|
||||||
if (response != null) {
|
|
||||||
print(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return AlertDialog(
|
|
||||||
content: SizedBox(
|
|
||||||
height: 200,
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
const Text(
|
|
||||||
'Ingresa la ubicación',
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
fontSize: 18,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
TextFormField(
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
hintText: 'Escribe tu ubicación',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
placeAutoComplete("Dubai");
|
|
||||||
},
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: const Color(0xFF2BA4EC),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(50),
|
|
||||||
),
|
|
||||||
elevation: 0,
|
|
||||||
minimumSize: const Size(230, 50),
|
|
||||||
),
|
|
||||||
child: const Text(
|
|
||||||
'Aceptar',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
fontSize: 18,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:prosappco/src/components/network_utility.dart';
|
||||||
|
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||||
|
|
||||||
|
class UbicacionScreen extends StatefulWidget {
|
||||||
|
const UbicacionScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<UbicacionScreen> createState() => _UbicacionScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _UbicacionScreenState extends State<UbicacionScreen> {
|
||||||
|
List<dynamic> _placesList = [];
|
||||||
|
String selectedPlace = '';
|
||||||
|
|
||||||
|
void placeAutoComplete(String query) async {
|
||||||
|
Uri uri = Uri.https("admin.prosapp.co", "/autocomplete", {
|
||||||
|
"input": query,
|
||||||
|
});
|
||||||
|
|
||||||
|
String? response = await NetworkUtility.fetchUrl(uri);
|
||||||
|
|
||||||
|
if (response != null) {
|
||||||
|
setState(() {
|
||||||
|
_placesList = jsonDecode(response.toString())['predictions'];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: PopAppbar(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
label: 'Tu ubicación'),
|
||||||
|
body: Center(
|
||||||
|
child: Container(
|
||||||
|
width: 300,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 20.0),
|
||||||
|
TextFormField(
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: 'Escribe tu ubicación',
|
||||||
|
prefixIcon: Icon(Icons.location_on),
|
||||||
|
),
|
||||||
|
onChanged: (value) {
|
||||||
|
String modifiedValue = value.replaceAll(' ', '_');
|
||||||
|
placeAutoComplete(modifiedValue);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20.0),
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: _placesList.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return ListTile(
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(
|
||||||
|
context, _placesList[index]['description']);
|
||||||
|
},
|
||||||
|
title: Text(_placesList[index]['description']),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user