notificacion desde cita
This commit is contained in:
@@ -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');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user