direccion para mobile

This commit is contained in:
Felipe
2023-08-17 15:38:20 -05:00
parent 08fd5e5dba
commit 0fff47fdac
2 changed files with 72 additions and 2 deletions
+70
View File
@@ -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<ServiceScreen> {
String _professional = '';
final DateFormat formatter = DateFormat('dd/MM/yyyy');
final DateTime now = DateTime.now();
List<dynamic> _placesList = [];
String selectedPlace = '';
String _coordsOfCity = '0.0,0.0';
DateTime? _selectedDate;
TimeOfDay? _selectedTime;
@@ -218,6 +222,14 @@ class _ServiceScreenState extends State<ServiceScreen> {
});
}
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<ServiceScreen> {
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<ServiceScreen> {
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: [