From fa1b373d5e24f13133d7c88736e9dc7abddffc29 Mon Sep 17 00:00:00 2001 From: Juan Felipe Duarte <70235683+DuarteJFelipe@users.noreply.github.com> Date: Wed, 21 Jun 2023 16:09:46 -0500 Subject: [PATCH] eliminar token y solicitud screen cambio de statefull a stateless --- .../authentication_repository.dart | 14 ++++++++++++- lib/src/components/drawer_menu.dart | 2 +- lib/src/components/drawer_professional.dart | 2 +- lib/src/screens/profile.dart | 2 +- lib/src/screens/profile_web.dart | 2 +- lib/src/screens/solicitudes.dart | 20 +------------------ lib/src/services/local_notifications.dart | 14 ++++++------- 7 files changed, 25 insertions(+), 31 deletions(-) diff --git a/lib/src/authentication/authentication_repository.dart b/lib/src/authentication/authentication_repository.dart index 2821463..5579550 100644 --- a/lib/src/authentication/authentication_repository.dart +++ b/lib/src/authentication/authentication_repository.dart @@ -3,6 +3,7 @@ import 'package:firebase_auth/firebase_auth.dart'; import 'package:get/get.dart'; import 'package:google_sign_in/google_sign_in.dart'; import 'package:prosappco/src/authentication/exceptions/register_failed.dart'; +import 'package:prosappco/src/models/event_model.dart'; import 'package:prosappco/src/screens/login.dart'; import 'package:prosappco/src/screens/service.dart'; @@ -151,7 +152,18 @@ class AuthenticationRepository extends GetxController { } } - Future logout() async => _auth.signOut(); + Future logout(String uid) async { + try { + await FirebaseFirestore.instance + .collection('users') + .doc(uid) + .update({'token': FieldValue.delete()}); + } catch (e) { + print(e); + } + + _auth.signOut(); + } String? getCurrentUserPhone() { final User? user = _auth.currentUser; diff --git a/lib/src/components/drawer_menu.dart b/lib/src/components/drawer_menu.dart index 5e3b698..7491041 100644 --- a/lib/src/components/drawer_menu.dart +++ b/lib/src/components/drawer_menu.dart @@ -366,7 +366,7 @@ class _DrawerMenuState extends State { const SizedBox(width: 10), ElevatedButton( onPressed: () { - AuthenticationRepository.instance.logout(); + AuthenticationRepository.instance.logout(uid!); }, style: ElevatedButton.styleFrom( backgroundColor: Colors.white, diff --git a/lib/src/components/drawer_professional.dart b/lib/src/components/drawer_professional.dart index 72336db..da49aef 100644 --- a/lib/src/components/drawer_professional.dart +++ b/lib/src/components/drawer_professional.dart @@ -357,7 +357,7 @@ class _DrawerProfessionalState extends State { const SizedBox(width: 10), ElevatedButton( onPressed: () { - AuthenticationRepository.instance.logout(); + AuthenticationRepository.instance.logout(uid!); }, style: ElevatedButton.styleFrom( backgroundColor: Colors.white, diff --git a/lib/src/screens/profile.dart b/lib/src/screens/profile.dart index 039dee7..12316c1 100644 --- a/lib/src/screens/profile.dart +++ b/lib/src/screens/profile.dart @@ -301,7 +301,7 @@ class _ProfileScreenState extends State { 'Inicie sesión para asegurarnos de que seas tú .', snackPosition: SnackPosition.BOTTOM, ); - AuthenticationRepository.instance.logout(); + AuthenticationRepository.instance.logout(uid!); } } } diff --git a/lib/src/screens/profile_web.dart b/lib/src/screens/profile_web.dart index fb36ccf..94e3988 100644 --- a/lib/src/screens/profile_web.dart +++ b/lib/src/screens/profile_web.dart @@ -238,7 +238,7 @@ class _ProfileWebScreenState extends State { 'Inicie sesión para asegurarnos de que seas tú .', snackPosition: SnackPosition.BOTTOM, ); - AuthenticationRepository.instance.logout(); + AuthenticationRepository.instance.logout(uid!); } } } diff --git a/lib/src/screens/solicitudes.dart b/lib/src/screens/solicitudes.dart index 8d21cbe..1feca14 100644 --- a/lib/src/screens/solicitudes.dart +++ b/lib/src/screens/solicitudes.dart @@ -8,29 +8,11 @@ import 'package:prosappco/src/models/event_model.dart'; import 'package:prosappco/src/models/scores_model.dart'; import 'package:prosappco/src/screens/cita.dart'; -// class name extends StatelessWidget { -// const name({super.key}); - -// @override -// Widget build(BuildContext context) { -// return Container(); -// } -// } -class SolicitudScreen extends StatefulWidget { +class SolicitudScreen extends StatelessWidget { SolicitudScreen({super.key}); - @override - State createState() => _SolicitudScreenState(); -} - -class _SolicitudScreenState extends State { DateTime today = DateTime.now(); - @override - void initState() { - super.initState(); - } - @override Widget build(BuildContext context) { return SafeArea( diff --git a/lib/src/services/local_notifications.dart b/lib/src/services/local_notifications.dart index ee0d3a9..10cabb0 100644 --- a/lib/src/services/local_notifications.dart +++ b/lib/src/services/local_notifications.dart @@ -1,13 +1,12 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:prosappco/src/services/firebase_messaging.dart'; - final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = -FlutterLocalNotificationsPlugin(); + FlutterLocalNotificationsPlugin(); Future initNotifications() async { const AndroidInitializationSettings initializationSettingsAndroid = - AndroidInitializationSettings('@mipmap/ic_launcher'); + AndroidInitializationSettings('@mipmap/ic_launcher'); const InitializationSettings initializationSettings = InitializationSettings( android: initializationSettingsAndroid, @@ -16,17 +15,18 @@ Future initNotifications() async { await flutterLocalNotificationsPlugin.initialize(initializationSettings); // Inicializar Firebase Messaging - FirebaseMessagingService firebaseMessagingService = FirebaseMessagingService(); + FirebaseMessagingService firebaseMessagingService = + FirebaseMessagingService(); await firebaseMessagingService.initializeFirebaseMessaging(); } Future showNotification(String title, String body) async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('solicitud_servicio', 'Solicitud de Servicio', - importance: Importance.max, priority: Priority.high); + AndroidNotificationDetails('solicitud_servicio', 'Solicitud de Servicio', + importance: Importance.max, priority: Priority.high); const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + NotificationDetails(android: androidNotificationDetails); await flutterLocalNotificationsPlugin.show( 1, title, body, notificationDetails);