From 0fff47fdac94e8e14e6a3b21104b2e54f7a98a66 Mon Sep 17 00:00:00 2001 From: Felipe Date: Thu, 17 Aug 2023 15:38:20 -0500 Subject: [PATCH] direccion para mobile --- lib/src/screens/service.dart | 70 ++++++++++++++++++++++++++++++++++++ pubspec.yaml | 4 +-- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/lib/src/screens/service.dart b/lib/src/screens/service.dart index 58c39a6..0fe4fed 100644 --- a/lib/src/screens/service.dart +++ b/lib/src/screens/service.dart @@ -22,6 +22,7 @@ import 'package:prosappco/src/screens/service_after.dart'; import 'package:prosappco/src/screens/service_type.dart'; import 'package:prosappco/src/screens/ubicacion.dart'; import 'package:http/http.dart' as http; +import 'package:prosappco/src/components/network_utility.dart'; class ServiceScreen extends StatefulWidget { const ServiceScreen({super.key}); @@ -99,6 +100,9 @@ class _ServiceScreenState extends State { String _professional = ''; final DateFormat formatter = DateFormat('dd/MM/yyyy'); final DateTime now = DateTime.now(); + List _placesList = []; + String selectedPlace = ''; + String _coordsOfCity = '0.0,0.0'; DateTime? _selectedDate; TimeOfDay? _selectedTime; @@ -218,6 +222,14 @@ class _ServiceScreenState extends State { }); } + if (_coordsOfCity == '0.0,0.0') { + AuthenticationRepository.instance + .getCoordsOfCity(uid.toString()) + .then((String s) => setState(() { + _coordsOfCity = s; + })); + } + _saveToken(); if (user == null) { @@ -281,6 +293,21 @@ class _ServiceScreenState extends State { return address; } + void placeAutoComplete(String query) async { + Uri uri = Uri.https("admin.prosapp.co", "/autocomplete", { + "input": query, + "location": _coordsOfCity, + }); + + String? response = await NetworkUtility.fetchUrl(uri); + + if (response != null) { + setState(() { + _placesList = jsonDecode(response.toString())['results']; + }); + } + } + @override Widget build(BuildContext context) { if (kIsWeb) { @@ -833,7 +860,50 @@ class _ServiceScreenState extends State { prefixIcon: Icon(Icons.near_me), hintText: 'Dirección', ), + onChanged: (value) { + String modifiedValue = + value.replaceAll(' ', '_'); + placeAutoComplete(modifiedValue); + }, ), + Container( + 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: [ diff --git a/pubspec.yaml b/pubspec.yaml index 9fe253b..4ff35aa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,7 +40,7 @@ dependencies: firebase_auth: ^4.6.2 firebase_core: ^2.13.1 file_picker: ^5.3.2 - google_sign_in: + google_sign_in: ^6.1.4 provider: get: font_awesome_flutter: ^10.4.0 @@ -54,6 +54,7 @@ dependencies: table_calendar: intl: google_maps_flutter: ^2.2.5 + http: ^0.13.5 geolocator: ^9.0.2 geocoding: ^2.1.0 url_launcher: ^6.1.10 @@ -63,7 +64,6 @@ dependencies: firebase_storage: ^11.2.2 responsive_builder: ^0.7.0 flutter_local_notifications: ^14.1.1 - http: ^0.13.5 flutter_dialogs: ^3.0.0 universal_html: ^2.2.3 firebase_messaging: ^14.6.3