coordernadas

This commit is contained in:
Juan Felipe Duarte
2023-06-16 15:42:07 -05:00
parent b7b246b03a
commit f69201e0dd
4 changed files with 93 additions and 30 deletions
+28 -7
View File
@@ -1,9 +1,10 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:prosappco/src/components/network_utility.dart';
import 'package:prosappco/src/components/pop_appbar.dart';
import '../authentication/authentication_repository.dart';
class UbicacionScreen extends StatefulWidget {
const UbicacionScreen({super.key});
@@ -14,17 +15,34 @@ class UbicacionScreen extends StatefulWidget {
class _UbicacionScreenState extends State<UbicacionScreen> {
List<dynamic> _placesList = [];
String selectedPlace = '';
String _coordsOfCity = '0.0,0.0';
@override
void initState() {
super.initState();
final uid = AuthenticationRepository.instance.getCurrentUserUid();
if (_coordsOfCity == '0.0,0.0') {
AuthenticationRepository.instance
.getCoordsOfCity(uid.toString())
.then((String s) => setState(() {
_coordsOfCity = s;
}));
}
}
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())['predictions'];
_placesList = jsonDecode(response.toString())['results'];
});
}
}
@@ -38,7 +56,7 @@ class _UbicacionScreenState extends State<UbicacionScreen> {
},
label: 'Tu ubicación'),
body: Center(
child: Container(
child: SizedBox(
width: 300,
child: Column(
children: [
@@ -60,10 +78,13 @@ class _UbicacionScreenState extends State<UbicacionScreen> {
itemBuilder: (context, index) {
return ListTile(
onTap: () {
Navigator.pop(
context, _placesList[index]['description']);
Navigator.pop(context, [
_placesList[index]['formatted_address'],
_placesList[index]['geometry']['location']['lat'],
_placesList[index]['geometry']['location']['lng']
]);
},
title: Text(_placesList[index]['description']),
title: Text(_placesList[index]['formatted_address']),
);
},
),