notificacion desde cita
This commit is contained in:
@@ -74,7 +74,6 @@ Future<List<Event>> getByProId(String day) async {
|
||||
event.id = element.id;
|
||||
eventos.add(event);
|
||||
}
|
||||
print('eventos $eventos');
|
||||
return eventos;
|
||||
} catch (e) {
|
||||
print('Error getByProId $e');
|
||||
@@ -96,7 +95,6 @@ Future<List<Event>> getByProIdAll(String state1, String state2) async {
|
||||
event.id = element.id;
|
||||
eventos.add(event);
|
||||
}
|
||||
print('eventos $eventos');
|
||||
return eventos;
|
||||
} catch (e) {
|
||||
print('Error getByProId $e');
|
||||
@@ -118,7 +116,6 @@ Future<List<Event>> getByUserIdAll(String state1, String state2) async {
|
||||
event.id = element.id;
|
||||
eventos.add(event);
|
||||
}
|
||||
print('eventos $eventos');
|
||||
return eventos;
|
||||
} catch (e) {
|
||||
print('Error getByUserId $e');
|
||||
@@ -211,7 +208,6 @@ class Event {
|
||||
for (var element in snapshot.docs) {
|
||||
eventos.add(Event.fromJson(element.data()));
|
||||
}
|
||||
print('eventos $eventos');
|
||||
return eventos;
|
||||
} catch (e) {
|
||||
print('Error getByProId $e');
|
||||
@@ -232,7 +228,6 @@ class Event {
|
||||
for (var element in snapshot.docs) {
|
||||
eventos.add(Event.fromJson(element.data()));
|
||||
}
|
||||
print('eventos $eventos');
|
||||
return eventos;
|
||||
} catch (e) {
|
||||
print('Error getByProId $e');
|
||||
|
||||
@@ -61,7 +61,6 @@ class SettingModel {
|
||||
|
||||
final Map<String, dynamic>? data = snapshot.data();
|
||||
|
||||
print('data $data');
|
||||
return fromJson(data!);
|
||||
} catch (e) {
|
||||
print('Error getting settings: $e');
|
||||
|
||||
@@ -32,7 +32,7 @@ class UserModel {
|
||||
json['token'],
|
||||
);
|
||||
} catch (e) {
|
||||
print('XD user $e');
|
||||
print('$e');
|
||||
return UserModel('', '', '', null, null, 0, '', '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:firebase_storage/firebase_storage.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -15,6 +16,9 @@ import 'package:prosappco/src/screens/chat.dart';
|
||||
import 'package:prosappco/src/screens/score.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:community_material_icon/community_material_icon.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/gestures.dart';
|
||||
|
||||
class CitaScreen extends StatefulWidget {
|
||||
final Event evento;
|
||||
@@ -29,12 +33,15 @@ class _CitaScreenState extends State<CitaScreen> {
|
||||
UserModel? user;
|
||||
DateTime today = DateTime.now();
|
||||
String nombre = '';
|
||||
String userToken = '';
|
||||
String numberPhone = '';
|
||||
int tarifa = 0;
|
||||
Reference? ref_photo;
|
||||
ScoresModel? scoresModel;
|
||||
bool? ver = true;
|
||||
bool? pro;
|
||||
String proName = '';
|
||||
late final FirebaseAuth _auth;
|
||||
|
||||
String formatCurrency(int number) {
|
||||
final formatter =
|
||||
@@ -42,12 +49,46 @@ class _CitaScreenState extends State<CitaScreen> {
|
||||
return '\$${formatter.format(number)}';
|
||||
}
|
||||
|
||||
Future<void> sendPushNotification(
|
||||
String user, String accion, String proName) async {
|
||||
try {
|
||||
http.Response response = await http.post(
|
||||
Uri.parse('https://fcm.googleapis.com/fcm/send'),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization':
|
||||
'key=AAAAORdR-xU:APA91bF_wblg86jHAC-uexrXPHavYRlk5wge1Gf46m56V4J2D2L37Cp_hf46JZUzpvsWPSpqc5ewHelKI9LTifUG_s2mciMI6e5VLKo7E1R8btbNo7iaM9do2ctoyHKUm1atlZBdKaN2',
|
||||
},
|
||||
body: jsonEncode(
|
||||
<String, dynamic>{
|
||||
'notification': <String, dynamic>{
|
||||
'body': accion == 'rechazo'
|
||||
? '$proName a rechazado tu solicitud de servicio'
|
||||
: '$proName a aprobado tu solicitud de servicio',
|
||||
'title': '$proName $accion',
|
||||
},
|
||||
'priority': 'high',
|
||||
'data': <String, dynamic>{
|
||||
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
|
||||
'id': '1',
|
||||
'status': 'done'
|
||||
},
|
||||
'to': user
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
response;
|
||||
} catch (e) {
|
||||
print('error al enviar notificacion $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openMap(double lat, double lng) async {
|
||||
final Uri _url =
|
||||
Uri.parse('https://www.google.com/maps/search/?api=1&query=$lat,$lng');
|
||||
|
||||
if (!await launchUrl(_url)) {
|
||||
print('hola');
|
||||
throw Exception('Could not launch $_url');
|
||||
}
|
||||
}
|
||||
@@ -65,6 +106,14 @@ class _CitaScreenState extends State<CitaScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||
_auth = FirebaseAuth.instance;
|
||||
|
||||
final currentUser = _auth.currentUser;
|
||||
if (currentUser != null && currentUser.displayName != null) {
|
||||
proName = currentUser.displayName!;
|
||||
}
|
||||
|
||||
if (settings == null) {
|
||||
SettingModel.getSettings().then(
|
||||
(SettingModel value) => setState(() {
|
||||
@@ -104,6 +153,7 @@ class _CitaScreenState extends State<CitaScreen> {
|
||||
setState(() {
|
||||
nombre = value.name;
|
||||
ref_photo = value.photo;
|
||||
userToken = value.token ?? '';
|
||||
numberPhone = value.phoneNumber ?? '';
|
||||
});
|
||||
});
|
||||
@@ -584,6 +634,10 @@ class _CitaScreenState extends State<CitaScreen> {
|
||||
.doc('${widget.evento.id}')
|
||||
.update({"status": "denegado"}).then(
|
||||
(value) {
|
||||
if (userToken != '') {
|
||||
sendPushNotification(
|
||||
userToken, 'rechazo', proName);
|
||||
}
|
||||
Navigator.pushReplacementNamed(
|
||||
context, '/solicitud');
|
||||
});
|
||||
@@ -625,6 +679,10 @@ class _CitaScreenState extends State<CitaScreen> {
|
||||
.doc('${widget.evento.id}')
|
||||
.update({"status": "aprobado"}).then(
|
||||
(value) {
|
||||
if (userToken != '') {
|
||||
sendPushNotification(
|
||||
userToken, 'acepto', proName);
|
||||
}
|
||||
Navigator.pushReplacementNamed(
|
||||
context, '/solicitud');
|
||||
});
|
||||
@@ -654,6 +712,10 @@ class _CitaScreenState extends State<CitaScreen> {
|
||||
.collection("services")
|
||||
.doc('${widget.evento.id}')
|
||||
.update({"status": "denegado"}).then((value) {
|
||||
if (userToken != '') {
|
||||
sendPushNotification(
|
||||
userToken, 'rechazo', proName);
|
||||
}
|
||||
Navigator.pushReplacementNamed(
|
||||
context, '/solicitud');
|
||||
});
|
||||
|
||||
@@ -62,7 +62,7 @@ Future<List<City>> getCountries() async {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('xd seqe $e');
|
||||
print('$e');
|
||||
}
|
||||
|
||||
return citys;
|
||||
@@ -116,8 +116,6 @@ class _CityScreenState extends State<CityScreen> {
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'coordsOfCity': coordsCity});
|
||||
|
||||
print('Ciudad actualizada correctamente');
|
||||
} catch (e) {
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
|
||||
@@ -44,7 +44,6 @@ class HorarioScreen extends StatelessWidget {
|
||||
await FirebaseFirestore.instance.collection('users').doc(uid).update({
|
||||
'horario': horariosMap,
|
||||
});
|
||||
print('Horarios actualizados correctamente');
|
||||
} catch (e) {
|
||||
print('Error al actualizar el horario: $e');
|
||||
}
|
||||
|
||||
@@ -70,7 +70,6 @@ class _MyServicesScreenState extends State<MyServicesScreen> {
|
||||
event.id = element.id;
|
||||
eventos.add(event);
|
||||
}
|
||||
print('eventos $eventos');
|
||||
return eventos;
|
||||
} catch (e) {
|
||||
print('Error getByProId $e');
|
||||
|
||||
@@ -65,7 +65,6 @@ class _MyServicesProScreenState extends State<MyServicesProScreen> {
|
||||
event.id = element.id;
|
||||
eventos.add(event);
|
||||
}
|
||||
print('eventos $eventos');
|
||||
return eventos;
|
||||
} catch (e) {
|
||||
print('Error getByProId $e');
|
||||
|
||||
@@ -22,7 +22,7 @@ Future<List<String>> getProfessions() async {
|
||||
|
||||
return professionsList;
|
||||
} catch (e) {
|
||||
print('xd $e');
|
||||
print('$e');
|
||||
}
|
||||
|
||||
return [];
|
||||
@@ -76,8 +76,6 @@ class _ProfessionScreenState extends State<ProfessionScreen> {
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'profesion': profession});
|
||||
|
||||
print('Profesion actualizada correctamente');
|
||||
} catch (e) {
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
|
||||
@@ -94,8 +94,6 @@ class _ProfessionalDireccionScreenState
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
});
|
||||
|
||||
print('Ciudad actualizada correctamente');
|
||||
} catch (e) {
|
||||
try {
|
||||
await FirebaseFirestore.instance.collection('users').doc(uid).set({
|
||||
|
||||
@@ -212,10 +212,8 @@ class ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
|
||||
|
||||
if (userSnapshot.exists) {
|
||||
await userRef.update({'imgCedula': image});
|
||||
print('¡Imagen de cédula actualizada correctamente!');
|
||||
} else {
|
||||
await userRef.set({'imgCedula': image});
|
||||
print('¡Imagen de cédula agregada correctamente!');
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error al agregar o actualizar la imagen de cédula: $e');
|
||||
@@ -257,10 +255,8 @@ class ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
|
||||
|
||||
if (userSnapshot.exists) {
|
||||
await userRef.update({'imgCertificado': image});
|
||||
print('¡Imagen de certificado actualizada correctamente!');
|
||||
} else {
|
||||
await userRef.set({'imgCertificado': image});
|
||||
print('¡Imagen de certificado agregada correctamente!');
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error al agregar o actualizar la imagen de certificado: $e');
|
||||
@@ -273,8 +269,6 @@ class ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'photo': image});
|
||||
|
||||
print('imagen actualizada correctamente');
|
||||
} catch (e) {
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
@@ -393,10 +387,8 @@ class ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
|
||||
|
||||
if (userSnapshot.exists) {
|
||||
await userRef.update({'imgEspecializaciones': photoPaths});
|
||||
print('¡Imágenes de especializaciones actualizadas correctamente!');
|
||||
} else {
|
||||
await userRef.set({'imgEspecializaciones': photoPaths});
|
||||
print('¡Imágenes de especializaciones agregadas correctamente!');
|
||||
}
|
||||
} catch (e) {
|
||||
print(
|
||||
|
||||
@@ -347,10 +347,8 @@ class _ProfessionalProfileWebScreenState
|
||||
|
||||
if (userSnapshot.exists) {
|
||||
await userRef.update({'imgCedula': image});
|
||||
print('¡Imagen de cédula actualizada correctamente!');
|
||||
} else {
|
||||
await userRef.set({'imgCedula': image});
|
||||
print('¡Imagen de cédula agregada correctamente!');
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error al agregar o actualizar la imagen de cédula: $e');
|
||||
@@ -364,10 +362,8 @@ class _ProfessionalProfileWebScreenState
|
||||
|
||||
if (userSnapshot.exists) {
|
||||
await userRef.update({'imgCertificado': image});
|
||||
print('¡Imagen de certificado actualizada correctamente!');
|
||||
} else {
|
||||
await userRef.set({'imgCertificado': image});
|
||||
print('¡Imagen de certificado agregada correctamente!');
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error al agregar o actualizar la imagen de certificado: $e');
|
||||
@@ -380,8 +376,6 @@ class _ProfessionalProfileWebScreenState
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'photo': image});
|
||||
|
||||
print('imagen actualizada correctamente');
|
||||
} catch (e) {
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
@@ -403,14 +397,9 @@ class _ProfessionalProfileWebScreenState
|
||||
|
||||
if (userSnapshot.exists) {
|
||||
await userRef.update({'imgEspecializaciones': filePaths});
|
||||
|
||||
print('¡Imágenes de especializaciones actualizadas correctamente!');
|
||||
} else {
|
||||
await userRef.set({'imgEspecializaciones': filePaths});
|
||||
print('¡Imágenes de especializaciones agregadas correctamente!');
|
||||
}
|
||||
|
||||
print('Archivos de especializaciones actualizados correctamente');
|
||||
} catch (e) {
|
||||
print('Error al actualizar los archivos de especializaciones: $e');
|
||||
}
|
||||
|
||||
@@ -87,7 +87,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
.doc(uid)
|
||||
.update({'photo': image});
|
||||
|
||||
print('imagen actualizada correctamente');
|
||||
} catch (e) {
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
@@ -246,7 +245,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
'name': newName,
|
||||
'lowerName': newName.toLowerCase(),
|
||||
});
|
||||
print('Nombre actualizado correctamente');
|
||||
} catch (e) {
|
||||
print('Error al actualizar el nombre: $e');
|
||||
}
|
||||
|
||||
@@ -303,8 +303,6 @@ class _ProfileProScreenState extends State<ProfileProScreen> {
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'banner': image});
|
||||
|
||||
print('imagen actualizada correctamente');
|
||||
} catch (e) {
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
|
||||
@@ -192,8 +192,6 @@ class _ProfileProWebScreenState extends State<ProfileProWebScreen> {
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'banner': image});
|
||||
|
||||
print('imagen actualizada correctamente');
|
||||
} catch (e) {
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
|
||||
@@ -153,7 +153,6 @@ class _ProfileWebScreenState extends State<ProfileWebScreen> {
|
||||
'name': newName,
|
||||
'lowerName': newName.toLowerCase(),
|
||||
});
|
||||
print('Nombre actualizado correctamente');
|
||||
} catch (e) {
|
||||
print('Error al actualizar el nombre: $e');
|
||||
}
|
||||
@@ -167,17 +166,15 @@ class _ProfileWebScreenState extends State<ProfileWebScreen> {
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (currentUser?.displayName != newName) {
|
||||
try {
|
||||
await FirebaseAuth.instance.currentUser!.updateDisplayName(newName);
|
||||
await FirebaseFirestore.instance.collection('users').doc(uid).update({
|
||||
'name': newName,
|
||||
'lowerName': newName.toLowerCase(),
|
||||
});
|
||||
print('Nombre actualizado correctamente');
|
||||
} catch (e) {
|
||||
print('Error al actualizar el nombre: $e');
|
||||
}
|
||||
|
||||
try {
|
||||
await FirebaseAuth.instance.currentUser!.updateDisplayName(newName);
|
||||
await FirebaseFirestore.instance.collection('users').doc(uid).update({
|
||||
'name': newName,
|
||||
'lowerName': newName.toLowerCase(),
|
||||
});
|
||||
} catch (e) {
|
||||
print('Error al actualizar el nombre: $e');
|
||||
}
|
||||
|
||||
if (currentUser?.email != newEmail) {
|
||||
@@ -202,7 +199,6 @@ class _ProfileWebScreenState extends State<ProfileWebScreen> {
|
||||
await FirebaseFirestore.instance.collection('users').doc(uid).update({
|
||||
'city': selectedCity,
|
||||
});
|
||||
print('Ciudad actualizada correctamente');
|
||||
} catch (e) {
|
||||
print('Error al actualizar la ciudad: $e');
|
||||
}
|
||||
@@ -243,8 +239,6 @@ class _ProfileWebScreenState extends State<ProfileWebScreen> {
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'photo': image});
|
||||
|
||||
print('imagen actualizada correctamente');
|
||||
} catch (e) {
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
|
||||
@@ -906,7 +906,6 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 15),
|
||||
Row(
|
||||
children: [
|
||||
|
||||
@@ -58,7 +58,6 @@ class SolicitudScreen extends StatelessWidget {
|
||||
event.id = element.id;
|
||||
eventos.add(event);
|
||||
}
|
||||
print('eventos $eventos');
|
||||
return eventos;
|
||||
} catch (e) {
|
||||
print('Error getByProId $e');
|
||||
|
||||
Reference in New Issue
Block a user