notificaciones

This commit is contained in:
Juan Felipe Duarte
2023-06-23 10:39:10 -05:00
parent fa1b373d5e
commit 90ec1293ea
12 changed files with 116 additions and 39 deletions
+50
View File
@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:firebase_storage/firebase_storage.dart';
@@ -19,6 +21,7 @@ import 'package:prosappco/src/screens/profile.dart';
import 'package:prosappco/src/screens/service_after.dart';
import 'package:prosappco/src/screens/service_type.dart';
import 'package:prosappco/src/screens/ubicacion.dart';
import 'package:http/http.dart' as http;
class ServiceScreen extends StatefulWidget {
const ServiceScreen({super.key});
@@ -43,6 +46,40 @@ class _ServiceScreenState extends State<ServiceScreen> {
}
}
Future<void> sendPushNotification(String token) 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': 'alguien a solicitado tus servicios',
'title': 'Nueva solicitud',
},
'priority': 'high',
'data': <String, dynamic>{
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
'id': '1',
'status': 'done'
},
'to': token,
},
),
);
print(token);
print(response);
response;
} catch (e) {
print('error al enviar notificacion $e');
}
}
EventoService eventoService = EventoService();
String _locationPosition = '';
String ubicacion = '';
@@ -52,6 +89,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
final TextEditingController _serviceTypeController = TextEditingController();
final TextEditingController _observacionController = TextEditingController();
String professionalId = '';
String professionalToken = '';
int? professionalTarifa;
String professionalAddress = '';
String professionalUbicacion = '';
@@ -453,6 +491,9 @@ class _ServiceScreenState extends State<ServiceScreen> {
false,
)
.then((value) {
if (professionalToken != '') {
sendPushNotification(professionalToken);
}
Navigator.pushReplacement(
context,
CupertinoPageRoute(
@@ -712,6 +753,11 @@ class _ServiceScreenState extends State<ServiceScreen> {
professionalId = profesional.id;
if (profesional.token != '') {
professionalToken =
profesional.token!;
}
professionalTarifa =
profesional.tarifa ?? 0;
@@ -914,6 +960,10 @@ class _ServiceScreenState extends State<ServiceScreen> {
false,
)
.then((value) {
if (professionalToken != '') {
sendPushNotification(
professionalToken);
}
Navigator.pushReplacement(
context,
CupertinoPageRoute(