mapa perfil profesional

This commit is contained in:
Juan Felipe Duarte
2023-04-22 19:02:24 -05:00
parent 03bd8401b5
commit 4f900db559
6 changed files with 320 additions and 128 deletions
@@ -1,6 +1,5 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:prosappco/src/authentication/exceptions/register_failed.dart';
@@ -163,6 +162,19 @@ class AuthenticationRepository extends GetxController {
return city;
}
Future<String> getAddress(String uid) async {
String address = '';
try {
final snapshot =
await FirebaseFirestore.instance.collection('users').doc(uid).get();
final Map<String, dynamic>? data = snapshot.data();
address = data?['address'] ?? '';
} catch (e) {
print('Error getting address: $e');
}
return address;
}
Future<String> getPhoto(String uid) async {
String photo = '';
try {
+257
View File
@@ -0,0 +1,257 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:geocoding/geocoding.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:prosappco/src/authentication/authentication_repository.dart';
import 'package:prosappco/src/components/pop_appbar.dart';
import 'package:prosappco/src/components/primary_btn.dart';
class ProfessionalDireccionScreen extends StatefulWidget {
const ProfessionalDireccionScreen({super.key});
@override
State<ProfessionalDireccionScreen> createState() =>
_ProfessionalDireccionScreenState();
}
class _ProfessionalDireccionScreenState
extends State<ProfessionalDireccionScreen> {
final TextEditingController _locationController = TextEditingController();
final String _locationPosition = '';
final uid = AuthenticationRepository.instance.getCurrentUserUid();
late GoogleMapController googleMapController;
static const CameraPosition initialCameraPosition = CameraPosition(
target: LatLng(7.8939100, -72.5078200),
zoom: 14.4746,
);
Set<Marker> markers = {};
Future<Position> _determinePosition() async {
bool serviceEnabled;
LocationPermission permission;
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
return Future.error('Location services are disabled');
}
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
return Future.error('Location permission denied');
}
}
if (permission == LocationPermission.deniedForever) {
return Future.error('Location permissions are permanently denied');
}
Position position = await Geolocator.getCurrentPosition();
return position;
}
@override
void initState() {
super.initState();
}
late String lat;
late String long;
var coordinates;
Future<String> getLocationName(double latitude, double longitude) async {
String address;
List<Placemark> placemarks =
await placemarkFromCoordinates(latitude, longitude);
Placemark place = placemarks[0];
if (place.thoroughfare != '' || place.subThoroughfare != '') {
address =
"${place.thoroughfare} ${place.subThoroughfare} ${place.subLocality}, ${place.locality}, ${place.administrativeArea}";
} else {
address = '';
}
return address;
}
Future<void> updateAddress(
String addressName, double latitude, double longitude) async {
try {
await FirebaseFirestore.instance.collection('users').doc(uid).update({
'address': addressName,
'latitude': latitude,
'longitude': longitude,
});
print('Ciudad actualizada correctamente');
} catch (e) {
try {
await FirebaseFirestore.instance.collection('users').doc(uid).set({
'address': addressName,
'latitude': latitude,
'longitude': longitude,
});
} catch (e) {
print('Error al agregar la ciudad: $e');
}
print('Error al actualizar la ciudad: $e');
}
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: PopAppbar(
onPressed: () {
Navigator.pop(context);
},
label: 'Ubicación'),
backgroundColor: const Color(0xFFD6F4FF),
body: Stack(
children: [
GoogleMap(
mapType: MapType.normal,
initialCameraPosition: initialCameraPosition,
markers: markers,
zoomControlsEnabled: false,
onMapCreated: (GoogleMapController controller) {
googleMapController = controller;
},
onCameraIdle: () {
if (coordinates != null) {
getLocationName(coordinates.latitude, coordinates.longitude)
.then((locationName) {
setState(() {
_locationController.text = locationName;
});
});
}
},
onCameraMove: (position) {
setState(() {
coordinates = position.target;
});
},
gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{
Factory<OneSequenceGestureRecognizer>(
() => EagerGestureRecognizer(),
),
},
),
Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 1,
blurRadius: 5,
offset: const Offset(0, 2),
),
],
),
child: Padding(
padding: const EdgeInsets.only(
left: 35, right: 35, bottom: 15, top: 5),
child: TextFormField(
controller: _locationController,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.near_me),
hintText: 'Dirección',
),
),
),
),
const Positioned(
bottom: 10,
right: 0,
left: 0,
top: 0,
child: Icon(
Icons.location_on,
size: 40,
color: Colors.red,
),
),
Positioned(
bottom: 130,
right: 20,
child: FloatingActionButton(
onPressed: () async {
try {
Position position = await _determinePosition();
googleMapController.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
target: LatLng(
position.latitude,
position.longitude,
),
zoom: 17),
),
);
setState(() {});
} catch (e) {
Get.snackbar(
'ubicación desactivada',
'Por favor activa la ubicacion de tu telefono.',
snackPosition: SnackPosition.TOP,
);
}
// markers.clear();
// markers.add(Marker(
// markerId: const MarkerId('currentLocation'),
// position:
// LatLng(position.latitude, position.longitude)));
},
elevation: 0,
child: const Icon(
Icons.gps_fixed,
size: 30,
),
),
),
Positioned(
bottom: 30,
left: 0,
right: 0,
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Align(
alignment: Alignment.center,
child: PrimaryButtom(
onPressed: () {
updateAddress(
_locationController.text,
coordinates.latitude,
coordinates.longitude,
);
Navigator.pop(context, _locationController.text);
},
label: 'Guardar'),
),
),
)
],
),
),
);
}
}
-15
View File
@@ -23,21 +23,6 @@ class _ProfessionalInfoScreenState extends State<ProfessionalInfoScreen> {
super.initState();
}
List<String> months = [
'enero',
'febrero',
'marzo',
'abril',
'mayo',
'junio',
'julio',
'agosto',
'septiembre',
'octubre',
'noviembre',
'diciembre',
];
@override
Widget build(BuildContext context) {
return SafeArea(
+6 -7
View File
@@ -132,14 +132,14 @@ class _ProfileScreenState extends State<ProfileScreen> {
_showChoiceDialog(context);
},
child: Container(
margin: EdgeInsets.symmetric(vertical: 50),
margin: const EdgeInsets.symmetric(vertical: 50),
width: 100,
height: 100,
decoration: BoxDecoration(
color: Color(0xFF2BA4EC),
color: const Color(0xFF2BA4EC),
borderRadius: BorderRadius.circular(50),
),
child: Icon(
child: const Icon(
Icons.person,
color: Colors.white,
size: 90,
@@ -189,7 +189,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
}
}
} catch (e) {
print('XD $e');
return GestureDetector(
onTap: () {
_showChoiceDialog(context);
@@ -302,7 +301,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
child: ListBody(
children: [
GestureDetector(
child: Text(
child: const Text(
textAlign: TextAlign.center,
"Tomar foto",
style: TextStyle(color: Color(0xFF2BA4EC)),
@@ -315,9 +314,9 @@ class _ProfileScreenState extends State<ProfileScreen> {
Navigator.of(context).pop();
},
),
Divider(color: Colors.black54),
const Divider(color: Colors.black54),
GestureDetector(
child: Text(
child: const Text(
textAlign: TextAlign.center,
"Abrir Galería",
style: TextStyle(color: Color(0xFF2BA4EC)),
+38 -92
View File
@@ -13,6 +13,7 @@ import 'package:prosappco/src/components/primary_btn.dart';
import 'package:prosappco/src/components/schedule_picker.dart';
import 'package:prosappco/src/screens/horario.dart';
import 'package:prosappco/src/screens/professional.dart';
import 'package:prosappco/src/screens/professional_direccion.dart';
import 'package:prosappco/src/services/select_image_profile.dart';
class ProfilePro extends StatefulWidget {
@@ -33,6 +34,8 @@ class _ProfileProState extends State<ProfilePro> {
var photoTemp = '';
var _photo = '...';
var _direccion = '...';
Map<String, Schedule>? _horarios;
@override
@@ -46,7 +49,6 @@ class _ProfileProState extends State<ProfilePro> {
(String s) => setState(
() {
_photo = s;
print('HOLA $s');
},
),
);
@@ -61,6 +63,14 @@ class _ProfileProState extends State<ProfilePro> {
),
);
}
if (_direccion == '...') {
AuthenticationRepository.instance
.getAddress(uid.toString())
.then((String s) => setState(() {
_direccion = s;
}));
}
}
Future<void> updateInfo() async {
@@ -77,94 +87,6 @@ class _ProfileProState extends State<ProfilePro> {
}
}
// Future<Widget> downloadImage(Reference ref) async {
// try {
// if (_photo == '...' || _photo.isEmpty) {
// return GestureDetector(
// onTap: () {
// _showChoiceDialog(context);
// },
// child: Container(
// margin: EdgeInsets.symmetric(vertical: 50),
// width: 100,
// height: 100,
// decoration: BoxDecoration(
// color: Color(0xFF2BA4EC),
// borderRadius: BorderRadius.circular(50),
// ),
// child: Icon(
// Icons.person,
// color: Colors.white,
// size: 90,
// ),
// ),
// );
// } else {
// final imageData = await ref.getData();
// if (imageData != null) {
// final widgetImage = GestureDetector(
// onTap: () {
// _showChoiceDialog(context);
// },
// child: Container(
// margin: const EdgeInsets.symmetric(vertical: 50),
// child: ClipOval(
// child: Image.memory(
// imageData,
// width: 60,
// height: 60,
// fit: BoxFit.cover,
// ),
// ),
// ),
// );
// return widgetImage;
// } else {
// return GestureDetector(
// onTap: () {
// _showChoiceDialog(context);
// },
// child: Container(
// margin: const EdgeInsets.symmetric(vertical: 50),
// width: 100,
// height: 100,
// decoration: BoxDecoration(
// color: const Color(0xFF2BA4EC),
// borderRadius: BorderRadius.circular(50),
// ),
// child: const Icon(
// Icons.person,
// color: Colors.white,
// size: 90,
// ),
// ),
// );
// }
// }
// } catch (e) {
// print('XD $e');
// return GestureDetector(
// onTap: () {
// _showChoiceDialog(context);
// },
// child: Container(
// margin: const EdgeInsets.symmetric(vertical: 50),
// width: 100,
// height: 100,
// decoration: BoxDecoration(
// color: const Color(0xFF2BA4EC),
// borderRadius: BorderRadius.circular(50),
// ),
// child: const Icon(
// Icons.person,
// color: Colors.white,
// size: 90,
// ),
// ),
// );
// }
// }
Future<void> updateImage(image) async {
try {
await FirebaseFirestore.instance
@@ -257,6 +179,8 @@ class _ProfileProState extends State<ProfilePro> {
@override
Widget build(BuildContext context) {
String address = _direccion.toString();
return SafeArea(
child: Scaffold(
appBar: AppBar(
@@ -317,9 +241,31 @@ class _ProfileProState extends State<ProfilePro> {
children: [
TextFormField(
// controller: _emailController,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.near_me),
hintText: 'Dirección'),
readOnly: true,
onTap: () async {
final String? direccion = await Navigator.push(
context,
CupertinoPageRoute(
builder: (BuildContext context) {
return const ProfessionalDireccionScreen();
},
),
) as String?;
if (direccion != null) {
setState(() {
_direccion = direccion;
});
}
},
decoration: InputDecoration(
prefixIcon: const Icon(Icons.near_me),
hintStyle: address == ''
? const TextStyle()
: const TextStyle(color: Colors.black87),
hintText:
address == '' ? 'Dirección' : address),
),
const SizedBox(height: 10),
TextFormField(
+6 -13
View File
@@ -121,7 +121,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
if (place.thoroughfare != '' || place.subThoroughfare != '') {
address =
"${place.thoroughfare}, ${place.subThoroughfare} ${place.subLocality}, ${place.locality}, ${place.administrativeArea}";
"${place.thoroughfare} ${place.subThoroughfare} ${place.subLocality}, ${place.locality}, ${place.administrativeArea}";
} else {
address = '';
}
@@ -164,16 +164,6 @@ class _ServiceScreenState extends State<ServiceScreen> {
});
}
},
// onCameraIdle: () {
// setState(() {
// if (coordinates != null) {
// placemarkFromCoordinates(coordinates.target.latitude, coordinates.target.longitude);
// _locationController.text = coordinates.toString();
// }
// });
// },
onCameraMove: (position) {
setState(() {
coordinates = position.target;
@@ -188,7 +178,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
),
),
const Positioned(
bottom: 0,
bottom: 10,
right: 0,
left: 0,
top: 0,
@@ -233,7 +223,10 @@ class _ServiceScreenState extends State<ServiceScreen> {
// LatLng(position.latitude, position.longitude)));
},
elevation: 0,
child: const Icon(Icons.location_on),
child: const Icon(
Icons.gps_fixed,
size: 30,
),
),
),
Padding(