diff --git a/lib/src/components/drawer_menu.dart b/lib/src/components/drawer_menu.dart index 0ffc78b..d18c82b 100644 --- a/lib/src/components/drawer_menu.dart +++ b/lib/src/components/drawer_menu.dart @@ -1,4 +1,3 @@ -import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -51,9 +50,8 @@ class _DrawerMenuState extends State { @override Widget build(BuildContext context) { - final userProvider = Provider.of(context); - - UserModel? user; + final userProvider = Provider.of(context, listen: false); + UserModel? user = userProvider.user; return Drawer( child: Column( @@ -62,19 +60,7 @@ class _DrawerMenuState extends State { color: Colors.white, child: Column( children: [ - StreamBuilder( - stream: userProvider.itemsStream, - builder: (BuildContext context, - AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center(child: CircularProgressIndicator()); - } else if (snapshot.hasError) { - return Center(child: Text('Error: ${snapshot.error}')); - } else { - return infoUser(context, snapshot.data); - } - }, - ), + infoUser(context, user), ], // ), ), @@ -117,6 +103,7 @@ class _DrawerMenuState extends State { ), ListTile( onTap: () { + Navigator.pop(context); if (kIsWeb) { Navigator.push( context, @@ -342,79 +329,64 @@ class _DrawerMenuState extends State { ), Column( children: [ - StreamBuilder( - stream: userProvider.itemsStream, - builder: - (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center(child: CircularProgressIndicator()); - } else if (snapshot.hasError) { - return Center(child: Text('Error: ${snapshot.error}')); + ElevatedButton( + onPressed: () { + UserModel? user = userProvider.user; + if (user?.name == '' || + user?.city == '' || + user?.phoneNumber == '' || + user?.phoneNumber == null) { + Get.snackbar( + 'Completa tu perfil', + 'Para ser un profesional registrado, asegúrate de llenar todos los campos necesarios y no olvides guardar tus cambios para que surtan efecto.', + snackPosition: SnackPosition.BOTTOM, + ); } else { - UserModel? user = snapshot.data; - - return ElevatedButton( - onPressed: () { - if (user?.name == '' || - user?.city == '' || - user?.phoneNumber == '' || - user?.phoneNumber == null) { - Get.snackbar( - 'Completa tu perfil', - 'Para ser un profesional registrado, asegúrate de llenar todos los campos necesarios y no olvides guardar tus cambios para que surtan efecto.', - snackPosition: SnackPosition.BOTTOM, + if (user?.phoneNumber != user?.phoneNumber) { + Get.snackbar( + 'Tu número de teléfono sigue sin cambios.', + 'Para guardar esta información, dirígete a tu perfil y selecciona la opción Guardar', + snackPosition: SnackPosition.BOTTOM, + ); + } else { + if (user?.state == 'pendiente' || user?.state == null) { + Navigator.pop(context); + if (kIsWeb) { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + const ProfessionalProfileWebScreen(), + ), ); } else { - if (user?.phoneNumber != user?.phoneNumber) { - Get.snackbar( - 'Tu número de teléfono sigue sin cambios.', - 'Para guardar esta información, dirígete a tu perfil y selecciona la opción Guardar', - snackPosition: SnackPosition.BOTTOM, - ); - } else { - if (user?.state == 'pendiente' || - user?.state == null) { - if (kIsWeb) { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => - const ProfessionalProfileWebScreen(), - ), - ); - } else { - Navigator.pushNamed( - context, '/profesionalProfile'); - } - } else if (user?.state == 'revision') { - Navigator.pushNamed( - context, '/profesionalRevision'); - } else if (user?.state == 'activo') { - Navigator.pushNamed(context, '/solicitud'); - } - } + Navigator.pushNamed(context, '/profesionalProfile'); } - }, - style: ElevatedButton.styleFrom( - backgroundColor: const Color(0xFF2BA4EC), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(50), - ), - elevation: 0, - minimumSize: const Size(230, 45), - ), - child: const Text( - 'Modo profesional', - style: TextStyle( - color: Colors.white, - fontSize: 15, - ), - ), - ); + } else if (user?.state == 'revision') { + Navigator.pushNamed(context, '/profesionalRevision'); + } else if (user?.state == 'activo') { + Navigator.pushNamed(context, '/solicitud'); + } + } } }, + style: ElevatedButton.styleFrom( + backgroundColor: const Color(0xFF2BA4EC), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(50), + ), + elevation: 0, + minimumSize: const Size(230, 45), + ), + child: const Text( + 'Modo profesional', + style: TextStyle( + color: Colors.white, + fontSize: 15, + ), + ), ), - const SizedBox(height: 10), + const SizedBox(height: 5), ElevatedButton( onPressed: () { AuthenticationRepository.instance.logout(uid!); diff --git a/lib/src/components/drawer_professional.dart b/lib/src/components/drawer_professional.dart index f9d2895..e8937a4 100644 --- a/lib/src/components/drawer_professional.dart +++ b/lib/src/components/drawer_professional.dart @@ -387,49 +387,47 @@ class _DrawerProfessionalState extends State { ], ), ), - Row( - children: [ - const SizedBox(width: 10), - ElevatedButton( - onPressed: () { - AuthenticationRepository.instance.logout(uid!); - }, - style: ElevatedButton.styleFrom( - backgroundColor: Colors.white, - shape: const CircleBorder(), - elevation: 3, - minimumSize: const Size(45, 45), - ), - child: const Icon( - Icons.logout_outlined, - color: Colors.red, - size: 35, - ), + ElevatedButton( + onPressed: () { + Navigator.pushReplacementNamed(context, '/servicio'); + }, + style: ElevatedButton.styleFrom( + backgroundColor: const Color(0xFF2BA4EC), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(50), ), - const SizedBox(width: 5), - ElevatedButton( - onPressed: () { - Navigator.pushReplacementNamed(context, '/servicio'); - }, - style: ElevatedButton.styleFrom( - backgroundColor: const Color(0xFF2BA4EC), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(50), - ), - elevation: 0, - minimumSize: const Size(200, 45), - ), - child: const Text( - 'Modo usuario', - style: TextStyle( - color: Colors.white, - fontSize: 15, - ), - ), + elevation: 0, + minimumSize: const Size(230, 45), + ), + child: const Text( + 'Modo usuario', + style: TextStyle( + color: Colors.white, + fontSize: 15, ), - ], + ), ), - const SizedBox(height: 10), + const SizedBox(height: 5), + ElevatedButton( + onPressed: () { + AuthenticationRepository.instance.logout(uid!); + }, + style: ElevatedButton.styleFrom( + backgroundColor: Colors.red, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(20)), + ), + minimumSize: const Size(230, 40), + ), + child: const Text( + 'Cerrar Sesión', + style: TextStyle( + color: Colors.white, + fontSize: 15, + ), + ), + ), + const SizedBox(height: 5), ], ), ), diff --git a/lib/src/providers/user_provider.dart b/lib/src/providers/user_provider.dart index d219d81..b2e9a74 100644 --- a/lib/src/providers/user_provider.dart +++ b/lib/src/providers/user_provider.dart @@ -5,19 +5,24 @@ import 'package:prosappco/src/models/user_model.dart'; class UserProvider extends ChangeNotifier { final FirebaseFirestore _firestore = FirebaseFirestore.instance; - Stream? _itemsStream; + UserModel? _user; UserProvider() { - _itemsStream = _firestore - .collection('users') - .doc(FirebaseAuth.instance.currentUser?.uid) - .snapshots() - .map((event) { - final data = event.data() as Map; - - return UserModel.fromFirestore(data); - }); + _loadUser(); } - Stream? get itemsStream => _itemsStream; + Future _loadUser() async { + final documentSnapshot = await _firestore + .collection('users') + .doc(FirebaseAuth.instance.currentUser?.uid) + .get(); + + if (documentSnapshot.exists) { + final data = documentSnapshot.data() as Map; + _user = UserModel.fromFirestore(data); + notifyListeners(); + } + } + + UserModel? get user => _user; }