This commit is contained in:
Juan Felipe Duarte
2023-04-29 17:56:29 -05:00
parent 0f90bc7ee9
commit 5baf019198
6 changed files with 460 additions and 99 deletions
+94 -48
View File
@@ -1,3 +1,4 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
@@ -27,7 +28,8 @@ class _ServiceScreenState extends State<ServiceScreen> {
EventoService eventoService = EventoService();
final TextEditingController _locationController = TextEditingController();
final String _locationPosition = '';
String _locationPosition = '';
String ubicacion = '';
final _profesionalController = TextEditingController();
final _serviceTypeController = TextEditingController();
final _observacionController = TextEditingController();
@@ -115,12 +117,44 @@ class _ServiceScreenState extends State<ServiceScreen> {
}
}
Future<List<DocumentSnapshot<Map<String, dynamic>>>>
getUsersWithActiveStatus() async {
var querySnapshot = await FirebaseFirestore.instance
.collection('users')
.where('estado', isEqualTo: 'activo')
.get();
return querySnapshot.docs;
}
final FirebaseStorage storage = FirebaseStorage.instance;
final uid = AuthenticationRepository.instance.getCurrentUserUid();
@override
void initState() {
super.initState();
try {
getUsersWithActiveStatus().then((value) {
for (var doc in value) {
final element = doc.data()!;
if (element['latitude'] != null && element['longitude'] != null) {
markers.add(
Marker(
markerId: MarkerId(doc.id),
position: LatLng(
element['latitude'],
element['longitude'],
),
),
);
}
}
});
} catch (e) {
print('error coordenadas $e');
}
}
late String lat;
@@ -191,14 +225,14 @@ class _ServiceScreenState extends State<ServiceScreen> {
),
),
const Positioned(
bottom: 10,
bottom: 25,
right: 0,
left: 0,
top: 0,
child: Icon(
Icons.location_on,
size: 40,
color: Colors.red,
color: Color(0xFFFF0000),
),
),
Positioned(
@@ -328,13 +362,17 @@ class _ServiceScreenState extends State<ServiceScreen> {
child: Form(
child: Column(
children: [
TextFormField(
readOnly: true,
controller: _locationController,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.near_me),
hintText: 'Dirección',
),
Column(
children: [
TextFormField(
readOnly: true,
controller: _locationController,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.near_me),
hintText: 'Dirección',
),
),
],
),
const SizedBox(height: 15),
TextFormField(
@@ -353,49 +391,45 @@ class _ServiceScreenState extends State<ServiceScreen> {
);
if (datos != null) {
Professional? profesional = datos[0];
ubicacion = datos[1];
if (profesional != null) {
setState(() {
_profesionalController.text =
profesional.name.toString();
professionalAddress =
profesional.realAddress;
professionalUbicacion =
profesional.ubicacion;
_locationController.text =
profesional.realAddress;
professionalLatitude =
profesional.latitude;
professionalLongitude =
profesional.longitude;
if (professionalLatitude != null &&
professionalLatitude != 0 &&
professionalLongitude != null &&
professionalLongitude != 0) {
markers.clear();
if (ubicacion == 'sitio') {
professionalAddress =
profesional.realAddress;
markers.add(Marker(
markerId:
const MarkerId('professional'),
position: LatLng(
professionalLatitude!,
professionalLongitude!)));
googleMapController.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
target: LatLng(
professionalLatitude!,
professionalLongitude!,
),
zoom: 17),
),
);
_locationController.text =
profesional.realAddress;
if (professionalLatitude != null &&
professionalLatitude != 0 &&
professionalLongitude != null &&
professionalLongitude != 0) {
googleMapController.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
target: LatLng(
professionalLatitude!,
professionalLongitude!,
),
zoom: 17),
),
);
}
}
professionalId = profesional.id;
});
}
@@ -472,24 +506,36 @@ class _ServiceScreenState extends State<ServiceScreen> {
TimeOfDay(hour: hora2, minute: minutos2);
UserModel.getUser(uid.toString()).then((value) {
eventoService.createEvent(
eventoService
.createEvent(
value.name,
_observacionController.text,
'${_selectedDate}Z',
_selectedTime!.format(context),
time2.format(context),
professionalId,
);
ubicacion,
_locationController.text,
ubicacion != 'sitio'
? coordinates.latitude
: professionalLatitude,
ubicacion != 'sitio'
? coordinates.longitude
: professionalLongitude,
)
.then((value) {
Navigator.push(
context,
CupertinoPageRoute(
builder: (BuildContext context) {
return ServiceAfterScreen(
eventoId: value,
);
},
),
);
});
});
// Navigator.push(
// context,
// CupertinoPageRoute(
// builder: (BuildContext context) {
// return const ServiceAfterScreen();
// },
// ),
// );
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF2BA4EC),