coordernadas
This commit is contained in:
@@ -176,6 +176,20 @@ class AuthenticationRepository extends GetxController {
|
||||
return city;
|
||||
}
|
||||
|
||||
Future<String> getCoordsOfCity(String uid) async {
|
||||
String coords = '';
|
||||
try {
|
||||
final snapshot =
|
||||
await FirebaseFirestore.instance.collection('users').doc(uid).get();
|
||||
final Map<String, dynamic>? data = snapshot.data();
|
||||
coords = data?['coordsOfCity'] ?? '';
|
||||
} catch (e) {
|
||||
print('Error getting coords of city: $e');
|
||||
}
|
||||
print('Error getting coords of city: $coords');
|
||||
return coords;
|
||||
}
|
||||
|
||||
Future<String> getAddress(String uid) async {
|
||||
String address = '';
|
||||
try {
|
||||
|
||||
+32
-14
@@ -17,13 +17,20 @@ final CollectionReference countriesCollection =
|
||||
|
||||
class City {
|
||||
String? cityName;
|
||||
String? coordsOfCity;
|
||||
String? stateOfCity;
|
||||
String? countryOfCity;
|
||||
|
||||
City({this.cityName, this.stateOfCity, this.countryOfCity});
|
||||
City({
|
||||
this.cityName,
|
||||
this.coordsOfCity,
|
||||
this.stateOfCity,
|
||||
this.countryOfCity,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "${cityName ?? ""}, ${stateOfCity ?? ""}, ${countryOfCity ?? ""}";
|
||||
return "${cityName ?? ""}, ${coordsOfCity ?? ""}, ${stateOfCity ?? ""}, ${countryOfCity ?? ""}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,27 +42,27 @@ Future<List<City>> getCountries() async {
|
||||
for (DocumentSnapshot country in countries.docs) {
|
||||
String countryName = country.id;
|
||||
Map<String, dynamic> data = country.data() as Map<String, dynamic>;
|
||||
Map<String, List<String>> states = {};
|
||||
Map<String, Map<String, String>> states = {};
|
||||
|
||||
for (var entry in data.entries) {
|
||||
String key = entry.key;
|
||||
List<String> value = List<String>.from(entry.value);
|
||||
states[key] = value;
|
||||
Map<String, String> cityData = Map<String, String>.from(entry.value);
|
||||
states[key] = cityData;
|
||||
}
|
||||
|
||||
for (var state in states.entries) {
|
||||
var citysState = state.value
|
||||
.map((cityName) => City(
|
||||
cityName: cityName,
|
||||
stateOfCity: state.key,
|
||||
countryOfCity: countryName))
|
||||
.toList();
|
||||
var citysState = state.value.entries.map((city) => City(
|
||||
cityName: city.key,
|
||||
coordsOfCity: city.value,
|
||||
stateOfCity: state.key,
|
||||
countryOfCity: countryName,
|
||||
));
|
||||
|
||||
citys.addAll(citysState);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('xd $e');
|
||||
print('xd seqe $e');
|
||||
}
|
||||
|
||||
return citys;
|
||||
@@ -98,13 +105,18 @@ class _CityScreenState extends State<CityScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateCity(String cityName) async {
|
||||
Future<void> updateCity(String cityName, String coordsCity) async {
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'city': cityName});
|
||||
|
||||
await FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'coordsOfCity': coordsCity});
|
||||
|
||||
print('Ciudad actualizada correctamente');
|
||||
} catch (e) {
|
||||
try {
|
||||
@@ -112,6 +124,11 @@ class _CityScreenState extends State<CityScreen> {
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.set({'city': cityName});
|
||||
|
||||
await FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.set({'coordsOfCity': coordsCity});
|
||||
} catch (e) {
|
||||
print('Error al agregar la ciudad: $e');
|
||||
}
|
||||
@@ -175,7 +192,8 @@ class _CityScreenState extends State<CityScreen> {
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
updateCity(citys[index].cityName ?? "");
|
||||
updateCity(citys[index].cityName ?? "",
|
||||
citys[index].coordsOfCity ?? "");
|
||||
Navigator.pop(context, citys[index].cityName ?? "");
|
||||
},
|
||||
);
|
||||
|
||||
@@ -13,7 +13,6 @@ import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||
import 'package:prosappco/src/components/drawer_menu.dart';
|
||||
import 'package:prosappco/src/models/event_model.dart';
|
||||
import 'package:prosappco/src/models/user_model.dart';
|
||||
import 'package:prosappco/src/screens/local_notification.dart';
|
||||
import 'package:prosappco/src/screens/professional.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:prosappco/src/screens/profile.dart';
|
||||
@@ -186,6 +185,10 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
|
||||
late String lat;
|
||||
late String long;
|
||||
|
||||
double latUser = 0.0;
|
||||
double lngUser = 0.0;
|
||||
|
||||
var coordinates;
|
||||
|
||||
Future<String> getLocationName(double latitude, double longitude) async {
|
||||
@@ -239,19 +242,24 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
controller: _ubicationController,
|
||||
readOnly: true,
|
||||
onTap: () async {
|
||||
final dynamic datos = await Navigator.push(
|
||||
final List<dynamic> datos = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return UbicacionScreen();
|
||||
return const UbicacionScreen();
|
||||
},
|
||||
),
|
||||
);
|
||||
print(datos);
|
||||
if (datos != null) {
|
||||
|
||||
if (datos.length == 3) {
|
||||
final formattedAddress = datos[0];
|
||||
final lat = datos[1];
|
||||
final lng = datos[2];
|
||||
|
||||
setState(() {
|
||||
_ubicationController.text = datos;
|
||||
print(_ubicationController.text);
|
||||
_ubicationController.text = formattedAddress;
|
||||
latUser = lat;
|
||||
lngUser = lng;
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -291,6 +299,8 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
if (ubicacion == 'sitio') {
|
||||
professionalAddress = profesional.realAddress;
|
||||
_ubicationController.text = profesional.realAddress;
|
||||
latUser = profesional.latitude;
|
||||
lngUser = profesional.longitude;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -419,8 +429,8 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
professionalId,
|
||||
ubicacion,
|
||||
professionalAddress,
|
||||
0.0,
|
||||
0.0,
|
||||
latUser,
|
||||
lngUser,
|
||||
'pendiente',
|
||||
professionalTarifa == 0 ? 0 : professionalTarifa,
|
||||
false,
|
||||
|
||||
@@ -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']),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user