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
+1 -1
View File
@@ -50,7 +50,7 @@ android {
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion "21".toInteger()
targetSdkVersion flutter.targetSdkVersion
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
+6 -4
View File
@@ -10,14 +10,15 @@ class UserModel {
final Reference? photo;
final int? tarifa;
final String? phoneNumber;
final String? token;
UserModel(this.name, this.city, this.profession, this.state, this.photo,
this.tarifa, this.phoneNumber);
this.tarifa, this.phoneNumber, this.token);
static Future<UserModel> fromJson(
Map<String, dynamic>? json, String uid) async {
try {
if (json == null) return UserModel('', '', '', null, null, 0, '');
if (json == null) return UserModel('', '', '', null, null, 0, '', '');
String? avatar = json['photo'];
return UserModel(
@@ -28,10 +29,11 @@ class UserModel {
avatar != null ? storage.ref().child(avatar) : null,
json['tarifa'] ?? 0,
json['phoneNumber'],
json['token'],
);
} catch (e) {
print('XD user $e');
return UserModel('', '', '', null, null, 0, '');
return UserModel('', '', '', null, null, 0, '', '');
}
}
@@ -43,7 +45,7 @@ class UserModel {
return fromJson(data, uid);
} catch (e) {
print('Error getting user: $e');
return UserModel('', '', '', null, null, 0, '');
return UserModel('', '', '', null, null, 0, '', '');
}
}
}
+1 -1
View File
@@ -99,7 +99,7 @@ class _CalendarScreenState extends State<CalendarScreen> {
return Scaffold(
floatingActionButtonLocation: kIsWeb
? FloatingActionButtonLocation.startFloat
: FloatingActionButtonLocation.startFloat,
: FloatingActionButtonLocation.endFloat,
resizeToAvoidBottomInset: false,
appBar: PopAppbar(
onPressed: () {
+17 -12
View File
@@ -40,6 +40,7 @@ class Professional {
final List<String> professionalEspecializado;
final ScoresModel scores;
final int? tarifa;
final String? token;
Professional({
required this.id,
@@ -54,6 +55,7 @@ class Professional {
required this.latitude,
required this.longitude,
this.tarifa,
this.token,
});
String getEspecializaciones() {
@@ -96,18 +98,20 @@ class Professional {
.toList();
Professional professional = Professional(
id: user.id,
name: data['name'],
professionName: data['profesion'],
cityName: data['city'],
professionalRef: storage.ref().child(photo),
professionalEspecializado: especializaciones,
ubicacion: data['ubicacion'] ?? '',
realAddress: data['address'] ?? '',
latitude: data['latitude'] ?? 0,
longitude: data['longitude'] ?? 0,
scores: await ScoresModel.scoreFrom(uid, true, true),
tarifa: data['tarifa'] ?? 0);
id: user.id,
name: data['name'],
professionName: data['profesion'],
cityName: data['city'],
professionalRef: storage.ref().child(photo),
professionalEspecializado: especializaciones,
ubicacion: data['ubicacion'] ?? '',
realAddress: data['address'] ?? '',
latitude: data['latitude'] ?? 0,
longitude: data['longitude'] ?? 0,
scores: await ScoresModel.scoreFrom(uid, true, true),
tarifa: data['tarifa'] ?? 0,
token: data['token'] ?? '',
);
return professional;
}
} catch (e) {
@@ -252,6 +256,7 @@ class _ProfessionalScreenState extends State<ProfessionalScreen> {
longitude: data['longitude'] ?? 0,
scores: await ScoresModel.scoreTo(user.id, true, true),
tarifa: data['tarifa'] ?? 0,
token: data['token'] ?? '',
);
professionals.add(professional);
}
+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(
@@ -6,10 +6,14 @@
#include "generated_plugin_registrant.h"
#include <awesome_notifications/awesome_notifications_plugin.h>
#include <file_selector_linux/file_selector_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) awesome_notifications_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "AwesomeNotificationsPlugin");
awesome_notifications_plugin_register_with_registrar(awesome_notifications_registrar);
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
+1
View File
@@ -3,6 +3,7 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
awesome_notifications
file_selector_linux
url_launcher_linux
)
@@ -5,6 +5,7 @@
import FlutterMacOS
import Foundation
import awesome_notifications
import cloud_firestore
import file_selector_macos
import firebase_auth
@@ -16,6 +17,7 @@ import geolocator_apple
import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AwesomeNotificationsPlugin.register(with: registry.registrar(forPlugin: "AwesomeNotificationsPlugin"))
FLTFirebaseFirestorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseFirestorePlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin"))
+29 -21
View File
@@ -25,6 +25,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.11.0"
awesome_notifications:
dependency: "direct main"
description:
name: awesome_notifications
sha256: "2b430c75cc879d6cfd52bb6eb2b5c1591ed425347816408cdcbd3f6916bba14c"
url: "https://pub.dev"
source: hosted
version: "0.7.4+1"
boolean_selector:
dependency: transitive
description:
@@ -141,10 +149,10 @@ packages:
dependency: "direct main"
description:
name: diacritic
sha256: c09a420e737dc036122121fea9f774767e95068f34a17894ee9db30c5bda3075
sha256: a84e03ec2779375fb86430dbe9d8fba62c68376f2499097a5f6e75556babe706
url: "https://pub.dev"
source: hosted
version: "0.1.3"
version: "0.1.4"
fake_async:
dependency: transitive
description:
@@ -197,10 +205,10 @@ packages:
dependency: transitive
description:
name: file_selector_platform_interface
sha256: "2a7f4bbf7bd2f022ecea85bfb1754e87f7dd403a9abc17a84a4fa2ddfe2abc0a"
sha256: "412705a646a0ae90f33f37acfae6a0f7cbc02222d6cd34e479421c3e74d3853c"
url: "https://pub.dev"
source: hosted
version: "2.5.1"
version: "2.6.0"
file_selector_windows:
dependency: transitive
description:
@@ -314,10 +322,10 @@ packages:
dependency: "direct main"
description:
name: flutter_animate
sha256: f611a67082d4c5ff9b8b7737ec7e675a22af70a94c8c3c22109f14b078d4d2bf
sha256: be54662837a6e66cc53ee88549e808c625275e0faf5a43e11cf3182cb0bd1b02
url: "https://pub.dev"
source: hosted
version: "4.1.1+1"
version: "4.2.0"
flutter_dialogs:
dependency: "direct main"
description:
@@ -516,10 +524,10 @@ packages:
dependency: "direct main"
description:
name: google_maps_flutter
sha256: "7b417a64ee7a060f42cf44d8c274d3b562423f6fe57d2911b7b536857c0d8eb6"
sha256: "7e35644d8a88ad86409976db8fa23ddc7d933f8239e57405e4660534be09acd2"
url: "https://pub.dev"
source: hosted
version: "2.3.0"
version: "2.3.1"
google_maps_flutter_android:
dependency: transitive
description:
@@ -628,10 +636,10 @@ packages:
dependency: transitive
description:
name: image_picker_android
sha256: "216dbfb6609e46f78613b8913d046a162588ad4f34909ae7bf85e9f94ea6d922"
sha256: d2bab152deb2547ea6f53d82ebca9b7e77386bb706e5789e815d37e08ea475bb
url: "https://pub.dev"
source: hosted
version: "0.8.7"
version: "0.8.7+3"
image_picker_for_web:
dependency: transitive
description:
@@ -684,10 +692,10 @@ packages:
dependency: "direct main"
description:
name: intl
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
sha256: "910f85bce16fb5c6f614e117efa303e85a1731bb0081edf3604a2ae6e9a3cc91"
url: "https://pub.dev"
source: hosted
version: "0.18.1"
version: "0.17.0"
intl_phone_field:
dependency: "direct main"
description:
@@ -889,10 +897,10 @@ packages:
dependency: "direct main"
description:
name: table_calendar
sha256: "1e3521a3e6d3fc7f645a58b135ab663d458ab12504f1ea7f9b4b81d47086c478"
sha256: "7f1270313c0cdb245b583ed8518982c01d4a7e95869b3c30abcbae3b642c45d0"
url: "https://pub.dev"
source: hosted
version: "3.0.9"
version: "3.0.8"
term_glyph:
dependency: transitive
description:
@@ -953,10 +961,10 @@ packages:
dependency: transitive
description:
name: url_launcher_android
sha256: eed4e6a1164aa9794409325c3b707ff424d4d1c2a785e7db67f8bbda00e36e51
sha256: "15f5acbf0dce90146a0f5a2c4a002b1814a6303c4c5c075aa2623b2d16156f03"
url: "https://pub.dev"
source: hosted
version: "6.0.35"
version: "6.0.36"
url_launcher_ios:
dependency: transitive
description:
@@ -985,10 +993,10 @@ packages:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "6c9ca697a5ae218ce56cece69d46128169a58aa8653c1b01d26fcd4aad8c4370"
sha256: bfdfa402f1f3298637d71ca8ecfe840b4696698213d5346e9d12d4ab647ee2ea
url: "https://pub.dev"
source: hosted
version: "2.1.2"
version: "2.1.3"
url_launcher_web:
dependency: transitive
description:
@@ -1057,10 +1065,10 @@ packages:
dependency: transitive
description:
name: win32
sha256: "7dacfda1edcca378031db9905ad7d7bd56b29fd1a90b0908b71a52a12c41e36b"
sha256: "1414f27dd781737e51afa9711f2ac2ace6ab4498ee98e20863fa5505aa00c58c"
url: "https://pub.dev"
source: hosted
version: "5.0.3"
version: "5.0.4"
xdg_directories:
dependency: transitive
description:
@@ -1079,4 +1087,4 @@ packages:
version: "6.3.0"
sdks:
dart: ">=3.0.0 <4.0.0"
flutter: ">=3.3.0"
flutter: ">=3.10.0"
+1
View File
@@ -67,6 +67,7 @@ dependencies:
flutter_dialogs: ^3.0.0
universal_html: ^2.2.3
firebase_messaging: ^14.6.3
awesome_notifications: ^0.7.4+1
dev_dependencies:
flutter_test:
@@ -6,12 +6,15 @@
#include "generated_plugin_registrant.h"
#include <awesome_notifications/awesome_notifications_plugin_c_api.h>
#include <file_selector_windows/file_selector_windows.h>
#include <firebase_core/firebase_core_plugin_c_api.h>
#include <geolocator_windows/geolocator_windows.h>
#include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
AwesomeNotificationsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AwesomeNotificationsPluginCApi"));
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
FirebaseCorePluginCApiRegisterWithRegistrar(
+1
View File
@@ -3,6 +3,7 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
awesome_notifications
file_selector_windows
firebase_core
geolocator_windows