From e99423063157c7252f65443d41515f92427a165b Mon Sep 17 00:00:00 2001 From: Juan Felipe Duarte <70235683+DuarteJFelipe@users.noreply.github.com> Date: Fri, 23 Jun 2023 21:55:10 -0500 Subject: [PATCH] prosapp changes --- lib/src/components/drawer_menu.dart | 21 -- lib/src/screens/chat.dart | 224 ++++++++++++------ lib/src/screens/local_notification.dart | 73 ------ lib/src/screens/messages.dart | 4 +- lib/src/screens/professional_profile_web.dart | 7 +- lib/src/screens/profile.dart | 9 + lib/src/screens/service.dart | 1 - linux/flutter/generated_plugin_registrant.cc | 4 + linux/flutter/generated_plugins.cmake | 1 + macos/Flutter/GeneratedPluginRegistrant.swift | 4 + pubspec.lock | 112 +++++++++ pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + 14 files changed, 292 insertions(+), 173 deletions(-) delete mode 100644 lib/src/screens/local_notification.dart diff --git a/lib/src/components/drawer_menu.dart b/lib/src/components/drawer_menu.dart index 7491041..cc2c071 100644 --- a/lib/src/components/drawer_menu.dart +++ b/lib/src/components/drawer_menu.dart @@ -8,7 +8,6 @@ import 'package:prosappco/src/components/photo_view.dart'; import 'package:prosappco/src/models/scores_model.dart'; import 'package:prosappco/src/models/user_model.dart'; import 'package:prosappco/src/screens/configuracion.dart'; -import 'package:prosappco/src/screens/local_notification.dart'; import 'package:prosappco/src/screens/messages_user.dart'; import 'package:prosappco/src/screens/professional_profile_web.dart'; import 'package:prosappco/src/screens/profile.dart'; @@ -233,26 +232,6 @@ class _DrawerMenuState extends State { style: TextStyle(fontSize: 15), ), ), - ListTile( - onTap: () { - Navigator.push( - context, - CupertinoPageRoute( - builder: (BuildContext context) { - return const LocalNotificationScreen(); - }, - ), - ); - }, - leading: const Icon( - Icons.notification_add_outlined, - color: Colors.black, - ), - title: const Text( - 'Notificación', - style: TextStyle(fontSize: 15), - ), - ), Builder(builder: (BuildContext context) { return ListTile( onTap: () { diff --git a/lib/src/screens/chat.dart b/lib/src/screens/chat.dart index 26068c2..0d35d48 100644 --- a/lib/src/screens/chat.dart +++ b/lib/src/screens/chat.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -10,6 +12,7 @@ import 'package:prosappco/src/models/event_model.dart'; import 'package:prosappco/src/models/user_model.dart'; import 'package:prosappco/src/screens/professional.dart'; import 'package:prosappco/src/screens/professional_info.dart'; +import 'package:http/http.dart' as http; class ChatScreen extends StatefulWidget { final String? eventoId; @@ -26,6 +29,40 @@ class _ChatScreenState extends State { Professional? professional; bool pro = false; + Future sendPushNotification(String token) async { + try { + http.Response response = await http.post( + Uri.parse('https://fcm.googleapis.com/fcm/send'), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': + 'key=AAAAORdR-xU:APA91bF_wblg86jHAC-uexrXPHavYRlk5wge1Gf46m56V4J2D2L37Cp_hf46JZUzpvsWPSpqc5ewHelKI9LTifUG_s2mciMI6e5VLKo7E1R8btbNo7iaM9do2ctoyHKUm1atlZBdKaN2', + }, + body: jsonEncode( + { + 'notification': { + 'body': 'Tienes un nuevo mensaje', + 'title': 'Nuevo mensaje', + }, + 'priority': 'high', + 'data': { + 'click_action': 'FLUTTER_NOTIFICATION_CLICK', + 'id': '1', + 'status': 'done' + }, + 'to': token, + }, + ), + ); + + print(token); + print(response); + response; + } catch (e) { + print('error al enviar notificacion $e'); + } + } + @override void initState() { super.initState(); @@ -141,7 +178,7 @@ class _ChatScreenState extends State { filled: true, fillColor: Colors.grey[200], ), - onFieldSubmitted: (value) { + onFieldSubmitted: (value) async { String muestra = _textController.text.trim(); if (muestra.isNotEmpty) { final nuevoMensaje = MessageModel( @@ -163,8 +200,28 @@ class _ChatScreenState extends State { 'message': FieldValue.arrayUnion([nuevoMensajeMap]) }); + if (user?.token != '') { + final mensajesQuerySnapshot = + await FirebaseFirestore.instance + .collection('chats') + .doc(widget.eventoId) + .get(); + final mensajes = + mensajesQuerySnapshot.data()?['message']; + if (mensajes != null && mensajes.isNotEmpty) { + final ultimoMensaje = mensajes.last; + final ultimoMensajeUser = ultimoMensaje['user']; + if (ultimoMensajeUser == uid) { + // El último mensaje fue enviado por ti, no se envía la notificación + } else { + sendPushNotification(user!.token!); + } + } else { + sendPushNotification(user!.token!); + } + } _textController.clear(); - } else {} + } }, ), ), @@ -192,8 +249,29 @@ class _ChatScreenState extends State { 'message': FieldValue.arrayUnion([nuevoMensajeMap]) }); + if (user?.token != '') { + final mensajesQuerySnapshot = await FirebaseFirestore + .instance + .collection('chats') + .doc(widget.eventoId) + .get(); + final mensajes = + mensajesQuerySnapshot.data()?['message']; + if (mensajes != null && mensajes.isNotEmpty) { + final ultimoMensaje = mensajes.last; + final ultimoMensajeUser = ultimoMensaje['user']; + if (ultimoMensajeUser == uid) { + // El último mensaje fue enviado por ti, no se envía la notificación + } else { + sendPushNotification(user!.token!); + } + } else { + sendPushNotification(user!.token!); + } + } + _textController.clear(); - } else {} + } }, child: Container( height: 50, @@ -233,81 +311,85 @@ class _ChatScreenState extends State { final data = snapshot.data!; final chat = ChatModel.fromDocumentSnapshot(data); - return Column(children: [ - ...chat.messages.map( - (e) => uid != e.user - ? ListTile( - title: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - margin: const EdgeInsets.only(right: 60), - padding: const EdgeInsets.symmetric( - vertical: 10, horizontal: 16), - decoration: BoxDecoration( - color: Colors.grey.shade200, - borderRadius: const BorderRadius.only( - topRight: Radius.circular(20), - bottomLeft: Radius.circular(20), - bottomRight: Radius.circular(20), + return Column( + children: [ + ...chat.messages.map( + (e) => uid != e.user + ? ListTile( + title: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + margin: const EdgeInsets.only(right: 60), + padding: const EdgeInsets.symmetric( + vertical: 10, horizontal: 16), + decoration: BoxDecoration( + color: Colors.grey.shade200, + borderRadius: const BorderRadius.only( + topRight: Radius.circular(20), + bottomLeft: Radius.circular(20), + bottomRight: Radius.circular(20), + ), + ), + child: Text( + e.content, + style: const TextStyle(fontSize: 16), ), ), - child: Text( - e.content, - style: const TextStyle(fontSize: 16), - ), - ), - const SizedBox(width: 5), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 10), - child: Text( - DateFormat('h:mm a').format(e.timestamp), - style: const TextStyle( - color: Colors.grey, fontSize: 12), - ), - ), - ], - ), - ) - : ListTile( - title: Column( - mainAxisAlignment: MainAxisAlignment.end, - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - Container( - margin: const EdgeInsets.only(left: 60), - padding: const EdgeInsets.symmetric( - vertical: 10, - horizontal: 16, - ), - decoration: const BoxDecoration( - color: Color(0xFFD5EFFF), - borderRadius: BorderRadius.only( - topLeft: Radius.circular(20), - bottomLeft: Radius.circular(20), - bottomRight: Radius.circular(20), + const SizedBox(width: 5), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: Text( + DateFormat('h:mm a').format(e.timestamp), + style: const TextStyle( + color: Colors.grey, fontSize: 12), ), ), - child: Text( - e.content, - style: const TextStyle(fontSize: 16), + ], + ), + ) + : ListTile( + title: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Container( + margin: const EdgeInsets.only(left: 60), + padding: const EdgeInsets.symmetric( + vertical: 10, + horizontal: 16, + ), + decoration: const BoxDecoration( + color: Color(0xFFD5EFFF), + borderRadius: BorderRadius.only( + topLeft: Radius.circular(20), + bottomLeft: Radius.circular(20), + bottomRight: Radius.circular(20), + ), + ), + child: Text( + e.content, + style: const TextStyle(fontSize: 16), + ), ), - ), - const SizedBox(width: 5), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 10), - child: Text( - DateFormat('h:mm a').format(e.timestamp), - style: const TextStyle( - color: Colors.grey, fontSize: 12), + const SizedBox(width: 5), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: Text( + DateFormat('h:mm a').format(e.timestamp), + style: const TextStyle( + color: Colors.grey, + fontSize: 12, + ), + ), ), - ), - ], + ], + ), ), - ), - ) - ]); + ) + ], + ); }, ); } diff --git a/lib/src/screens/local_notification.dart b/lib/src/screens/local_notification.dart deleted file mode 100644 index de99969..0000000 --- a/lib/src/screens/local_notification.dart +++ /dev/null @@ -1,73 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_dialogs/flutter_dialogs.dart'; -import 'package:prosappco/src/components/pop_appbar.dart'; -import 'package:prosappco/src/services/local_notifications.dart'; - -class LocalNotificationScreen extends StatelessWidget { - const LocalNotificationScreen({Key? key}) : super(key: key); - - void showCustomDialog(BuildContext context, String title, String content) { - showPlatformDialog( - context: context, - builder: (_) => BasicDialogAlert( - title: Text(title), - content: Text(content), - actions: [ - BasicDialogAction( - onPressed: () { - Navigator.pop(context); - }, - title: const Text('Cerrar'), - ), - ], - ), - ); - } - - @override - Widget build(BuildContext context) { - if (kIsWeb) { - return Scaffold( - appBar: PopAppbar( - onPressed: () { - Navigator.pop(context); - }, - label: 'Notificaciones', - ), - body: Center( - child: ElevatedButton( - onPressed: () { - showCustomDialog( - context, - 'Nueva notificación!', - 'Esta es una notificación de Flutter', - ); - }, - child: const Text('Lanzar notificación'), - ), - ), - ); - } else { - return Scaffold( - appBar: PopAppbar( - onPressed: () { - Navigator.pop(context); - }, - label: 'Notificaciones', - ), - body: Center( - child: ElevatedButton( - onPressed: () { - showNotification( - 'Nueva notificación!', - 'Esta es una notificación de prosapp!', - ); - }, - child: const Text('Lanzar notificación'), - ), - ), - ); - } - } -} diff --git a/lib/src/screens/messages.dart b/lib/src/screens/messages.dart index f4ab0a3..dd58caa 100644 --- a/lib/src/screens/messages.dart +++ b/lib/src/screens/messages.dart @@ -69,10 +69,10 @@ class _MessagesScreenState extends State { size: 55, sizeCircle: 60, ), - trailing: Column( + trailing: const Column( children: [ SizedBox(height: 8), - const Icon( + Icon( Icons.keyboard_arrow_right, color: Colors.black, ), diff --git a/lib/src/screens/professional_profile_web.dart b/lib/src/screens/professional_profile_web.dart index 8a548f1..8c12a14 100644 --- a/lib/src/screens/professional_profile_web.dart +++ b/lib/src/screens/professional_profile_web.dart @@ -257,10 +257,7 @@ class _ProfessionalProfileWebScreenState .child('cedula') .child(random); - final metaData = SettableMetadata(contentType: 'image/jpeg'); - // final metaDataImg = SettableMetadata(contentType: 'image/jpeg'); - // final metaDataPdf = SettableMetadata(contentType: 'application/pdf'); - // final metaDataWord = SettableMetadata(contentType: 'application/msword'); + final metaData = SettableMetadata(contentType: 'application/pdf'); final UploadTask uploadTask = ref.putData(imageCedulaBytes!, metaData); @@ -293,7 +290,7 @@ class _ProfessionalProfileWebScreenState .child('certificado_profesional') .child(random); - final metaData = SettableMetadata(contentType: 'image/jpeg'); + final metaData = SettableMetadata(contentType: 'application/pdf'); final UploadTask uploadTask = ref.putData(imageCertificadoBytes!, metaData); diff --git a/lib/src/screens/profile.dart b/lib/src/screens/profile.dart index 12316c1..a5dac7a 100644 --- a/lib/src/screens/profile.dart +++ b/lib/src/screens/profile.dart @@ -276,6 +276,15 @@ class _ProfileScreenState extends State { print('e'); } + try { + await FirebaseFirestore.instance + .collection('users') + .doc(uid) + .update({'email': newEmail}); + } catch (e) { + print('e'); + } + try { if (imagen_to_upload == null) { return; diff --git a/lib/src/screens/service.dart b/lib/src/screens/service.dart index 5040fbb..83f6f88 100644 --- a/lib/src/screens/service.dart +++ b/lib/src/screens/service.dart @@ -1,5 +1,4 @@ import 'dart:convert'; - import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:firebase_storage/firebase_storage.dart'; diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 0f5e8dc..819a643 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,11 +6,15 @@ #include "generated_plugin_registrant.h" +#include #include #include #include void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) audioplayers_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "AudioplayersLinuxPlugin"); + audioplayers_linux_plugin_register_with_registrar(audioplayers_linux_registrar); g_autoptr(FlPluginRegistrar) awesome_notifications_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "AwesomeNotificationsPlugin"); awesome_notifications_plugin_register_with_registrar(awesome_notifications_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 3b861be..03c86af 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + audioplayers_linux awesome_notifications file_selector_linux url_launcher_linux diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 412a16d..b883437 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,6 +5,7 @@ import FlutterMacOS import Foundation +import audioplayers_darwin import awesome_notifications import cloud_firestore import file_selector_macos @@ -14,9 +15,11 @@ import firebase_messaging import firebase_storage import flutter_local_notifications import geolocator_apple +import path_provider_foundation import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin")) AwesomeNotificationsPlugin.register(with: registry.registrar(forPlugin: "AwesomeNotificationsPlugin")) FLTFirebaseFirestorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseFirestorePlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) @@ -26,5 +29,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTFirebaseStoragePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseStoragePlugin")) FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin")) + PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index fd50ffb..073f77a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -25,6 +25,62 @@ packages: url: "https://pub.dev" source: hosted version: "2.11.0" + audioplayers: + dependency: "direct main" + description: + name: audioplayers + sha256: "61583554386721772f9309f509e17712865b38565a903c761f96b1115a979282" + url: "https://pub.dev" + source: hosted + version: "4.1.0" + audioplayers_android: + dependency: transitive + description: + name: audioplayers_android + sha256: dbdc9b7f2aa2440314c638aa55aadd45c7705e8340d5eddf2e3fb8da32d4ae2c + url: "https://pub.dev" + source: hosted + version: "3.0.2" + audioplayers_darwin: + dependency: transitive + description: + name: audioplayers_darwin + sha256: "6aea96df1d12f7ad5a71d88c6d1b22a216211a9564219920124c16768e456e9d" + url: "https://pub.dev" + source: hosted + version: "4.1.0" + audioplayers_linux: + dependency: transitive + description: + name: audioplayers_linux + sha256: "396b62ac62c92dd26c3bc5106583747f57a8b325ebd2b41e5576f840cfc61338" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + audioplayers_platform_interface: + dependency: transitive + description: + name: audioplayers_platform_interface + sha256: f7daaed4659143094151ecf6bacd927d29ab8acffba98c110c59f0b81ae51143 + url: "https://pub.dev" + source: hosted + version: "5.0.1" + audioplayers_web: + dependency: transitive + description: + name: audioplayers_web + sha256: ec84fd46eed1577148ed4113f5998a36a18da4fce7170c37ce3e21b631393339 + url: "https://pub.dev" + source: hosted + version: "3.1.0" + audioplayers_windows: + dependency: transitive + description: + name: audioplayers_windows + sha256: "1d3aaac98a192b8488167711ba1e67d8b96333e8d0572ede4e2912e5bbce69a3" + url: "https://pub.dev" + source: hosted + version: "2.0.2" awesome_notifications: dependency: "direct main" description: @@ -776,6 +832,54 @@ packages: url: "https://pub.dev" source: hosted version: "1.8.3" + path_provider: + dependency: transitive + description: + name: path_provider + sha256: "3087813781ab814e4157b172f1a11c46be20179fcc9bea043e0fba36bc0acaa2" + url: "https://pub.dev" + source: hosted + version: "2.0.15" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + sha256: "2cec049d282c7f13c594b4a73976b0b4f2d7a1838a6dd5aaf7bd9719196bee86" + url: "https://pub.dev" + source: hosted + version: "2.0.27" + path_provider_foundation: + dependency: transitive + description: + name: path_provider_foundation + sha256: "1995d88ec2948dac43edf8fe58eb434d35d22a2940ecee1a9fefcd62beee6eb3" + url: "https://pub.dev" + source: hosted + version: "2.2.3" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + sha256: ffbb8cc9ed2c9ec0e4b7a541e56fd79b138e8f47d2fb86815f15358a349b3b57 + url: "https://pub.dev" + source: hosted + version: "2.1.11" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + sha256: "57585299a729335f1298b43245842678cb9f43a6310351b18fb577d6e33165ec" + url: "https://pub.dev" + source: hosted + version: "2.0.6" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + sha256: "1cb68ba4cd3a795033de62ba1b7b4564dace301f952de6bfb3cd91b202b6ee96" + url: "https://pub.dev" + source: hosted + version: "2.1.7" petitparser: dependency: transitive description: @@ -893,6 +997,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.0" + synchronized: + dependency: transitive + description: + name: synchronized + sha256: "5fcbd27688af6082f5abd611af56ee575342c30e87541d0245f7ff99faa02c60" + url: "https://pub.dev" + source: hosted + version: "3.1.0" table_calendar: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 8714379..e689512 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -68,6 +68,7 @@ dependencies: universal_html: ^2.2.3 firebase_messaging: ^14.6.3 awesome_notifications: ^0.7.4+1 + audioplayers: ^4.1.0 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index d7253b0..5243c88 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,7 @@ #include "generated_plugin_registrant.h" +#include #include #include #include @@ -13,6 +14,8 @@ #include void RegisterPlugins(flutter::PluginRegistry* registry) { + AudioplayersWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin")); AwesomeNotificationsPluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("AwesomeNotificationsPluginCApi")); FileSelectorWindowsRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index a4eaa73..87c6552 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + audioplayers_windows awesome_notifications file_selector_windows firebase_core