From 029164404a560557d66ccafa0fdbf3bebf53469a Mon Sep 17 00:00:00 2001 From: Juan Felipe Duarte <70235683+DuarteJFelipe@users.noreply.github.com> Date: Sun, 9 Apr 2023 10:03:57 -0500 Subject: [PATCH] botones --- .../authentication_repository.dart | 17 +- lib/src/screens/professional_profile.dart | 2 +- lib/src/screens/professional_revision.dart | 2 +- lib/src/screens/profile.dart | 15 +- lib/src/screens/welcome.dart | 198 +++++++++--------- 5 files changed, 136 insertions(+), 98 deletions(-) diff --git a/lib/src/authentication/authentication_repository.dart b/lib/src/authentication/authentication_repository.dart index e338e4c..d289580 100644 --- a/lib/src/authentication/authentication_repository.dart +++ b/lib/src/authentication/authentication_repository.dart @@ -27,7 +27,9 @@ class AuthenticationRepository extends GetxController { } _setInitialScreen(User? user) { - user == null ? Get.offAll(LoginScreen()) : Get.offAll(WelcomeScreen()); + user == null + ? Get.offAll(const LoginScreen()) + : Get.offAll(const WelcomeScreen()); } Future phoneAuthentication(String phoneNo) async { @@ -156,4 +158,17 @@ class AuthenticationRepository extends GetxController { } return photo; } + + Future getState(String uid) async { + String state = ''; + try { + final snapshot = + await FirebaseFirestore.instance.collection('users').doc(uid).get(); + final Map? data = snapshot.data(); + state = data?['estado'] ?? ''; + } catch (e) { + print('Error getting estado: $e'); + } + return state; + } } diff --git a/lib/src/screens/professional_profile.dart b/lib/src/screens/professional_profile.dart index 52b0e2d..efb3956 100644 --- a/lib/src/screens/professional_profile.dart +++ b/lib/src/screens/professional_profile.dart @@ -18,7 +18,7 @@ class ProfessionalProfileScreenState extends State { leading: IconButton( icon: Icon(Icons.arrow_back), onPressed: () { - Navigator.pushReplacementNamed(context, '/profile'); + Navigator.pop(context); }, ), iconTheme: IconThemeData( diff --git a/lib/src/screens/professional_revision.dart b/lib/src/screens/professional_revision.dart index 74838f4..7886822 100644 --- a/lib/src/screens/professional_revision.dart +++ b/lib/src/screens/professional_revision.dart @@ -19,7 +19,7 @@ class _ProfessionalRevisionScreenState leading: IconButton( icon: Icon(Icons.arrow_back), onPressed: () { - Navigator.pushReplacementNamed(context, '/profile'); + Navigator.pop(context); }, ), iconTheme: IconThemeData( diff --git a/lib/src/screens/profile.dart b/lib/src/screens/profile.dart index 92848b6..502cddb 100644 --- a/lib/src/screens/profile.dart +++ b/lib/src/screens/profile.dart @@ -33,6 +33,7 @@ class _ProfileScreenState extends State { var photoTemp = ''; var _ciudad = '...'; var _photo = '...'; + var _estado = '...'; @override void initState() { @@ -68,6 +69,13 @@ class _ProfileScreenState extends State { _photo = s; })); } + if (_estado == '...') { + AuthenticationRepository.instance + .getState(uid.toString()) + .then((String s) => setState(() { + _estado = s; + })); + } } Future updateImage(image) async { @@ -320,6 +328,7 @@ class _ProfileScreenState extends State { final User? user = FirebaseAuth.instance.currentUser; String city = _ciudad.toString(); + String state = _estado.toString(); return SafeArea( child: Scaffold( @@ -508,7 +517,11 @@ class _ProfileScreenState extends State { SizedBox(width: 5), ElevatedButton( onPressed: () { - Navigator.pushNamed(context, '/profesionalRevision'); + if (state == 'pendiente') { + Navigator.pushNamed(context, '/profesionalProfile'); + } else if (state == 'revision') { + Navigator.pushNamed(context, '/profesionalRevision'); + } }, child: Text( 'Modo profesional', diff --git a/lib/src/screens/welcome.dart b/lib/src/screens/welcome.dart index b837d74..5cbfa11 100644 --- a/lib/src/screens/welcome.dart +++ b/lib/src/screens/welcome.dart @@ -1,11 +1,10 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_storage/firebase_storage.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:prosappco/src/authentication/authentication_repository.dart'; -import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:prosappco/src/controllers/add_name_email_city.dart'; -import 'package:prosappco/src/screens/profile.dart'; import '../components/photo_view.dart'; @@ -19,15 +18,29 @@ class WelcomeScreen extends StatefulWidget { class _WelcomeScreenState extends State { final FirebaseStorage storage = FirebaseStorage.instance; final uid = AuthenticationRepository.instance.getCurrentUserUid(); - final _formKey = GlobalKey(); final controller = Get.put(NameEmailCityController()); var _ciudad = ''; var _photo = '...'; + var _estado = '...'; @override void initState() { super.initState(); - final Reference ref = storage.ref().child(_photo); + + if (_estado == '...') { + AuthenticationRepository.instance + .getState(uid.toString()) + .then((String s) => setState(() { + _estado = s; + + if (_estado.isEmpty) { + FirebaseFirestore.instance + .collection('users') + .doc(uid) + .update({'estado': 'pendiente'}); + } + })); + } if (_ciudad == '') { AuthenticationRepository.instance @@ -36,6 +49,7 @@ class _WelcomeScreenState extends State { _ciudad = s; })); } + if (_photo == '...') { AuthenticationRepository.instance .getPhoto(uid.toString()) @@ -51,6 +65,7 @@ class _WelcomeScreenState extends State { // String name = _nombre.toString(); String city = _ciudad.toString(); + String state = _estado.toString(); return SafeArea( child: Scaffold( @@ -62,48 +77,46 @@ class _WelcomeScreenState extends State { children: [ Column( children: [ - Container( - child: ListTile( - onTap: () { - Navigator.pushNamed(context, '/profile'); - }, - title: Text(user?.displayName ?? '', - style: TextStyle(fontWeight: FontWeight.bold)), - subtitle: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - user?.phoneNumber ?? '', - style: TextStyle(fontSize: 12), - ), - Text( - city, - style: TextStyle(fontSize: 12), - ), - ], - ), - leading: ReferencePhoto( - ref: storage.ref().child(_photo), - size: 50, - ), - trailing: Icon(Icons.keyboard_arrow_right, - color: Colors.black), - contentPadding: - EdgeInsets.symmetric(vertical: 20, horizontal: 16), + ListTile( + onTap: () { + Navigator.pushNamed(context, '/profile'); + }, + title: Text(user?.displayName ?? '', + style: const TextStyle(fontWeight: FontWeight.bold)), + subtitle: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + user?.phoneNumber ?? '', + style: const TextStyle(fontSize: 12), + ), + Text( + city, + style: const TextStyle(fontSize: 12), + ), + ], ), + leading: ReferencePhoto( + ref: storage.ref().child(_photo), + size: 50, + ), + trailing: const Icon(Icons.keyboard_arrow_right, + color: Colors.black), + contentPadding: const EdgeInsets.symmetric( + vertical: 20, horizontal: 16), ), ], // padding: const EdgeInsets.only(top: 20, bottom: 15), ), - Divider(height: 0, color: Colors.grey), + const Divider(height: 0, color: Colors.grey), Column( children: [ ListTile( onTap: () {}, - leading: Icon( + leading: const Icon( Icons.history, color: Colors.black, ), - title: Text( + title: const Text( 'Mis servicios', style: TextStyle(fontSize: 15), ), @@ -112,44 +125,44 @@ class _WelcomeScreenState extends State { onTap: () { Navigator.pushNamed(context, '/profile'); }, - leading: Icon( + leading: const Icon( Icons.person_outline, color: Colors.black, ), - title: Text( + title: const Text( 'Mi perfil', style: TextStyle(fontSize: 15), ), ), ListTile( onTap: () {}, - leading: Icon( + leading: const Icon( Icons.construction_outlined, color: Colors.black, ), - title: Text( + title: const Text( 'Configuración', style: TextStyle(fontSize: 15), ), ), ListTile( onTap: () {}, - leading: Icon( + leading: const Icon( Icons.question_mark_rounded, color: Colors.black, ), - title: Text( + title: const Text( 'Soporte', style: TextStyle(fontSize: 15), ), ), ListTile( onTap: () {}, - leading: Icon( + leading: const Icon( Icons.messenger_outline, color: Colors.black, ), - title: Text( + title: const Text( 'Mensajes', style: TextStyle(fontSize: 15), ), @@ -159,20 +172,20 @@ class _WelcomeScreenState extends State { onTap: () { Scaffold.of(context).openEndDrawer(); }, - trailing: Icon( + trailing: const Icon( Icons.keyboard_arrow_right, color: Colors.white, ), - title: Text( + title: const Text( 'Solicitar servicio', style: TextStyle( color: Colors.white, fontSize: 17, fontWeight: FontWeight.bold), ), - tileColor: Color(0xFF2BA4EC), - contentPadding: - EdgeInsets.symmetric(vertical: 5, horizontal: 16), + tileColor: const Color(0xFF2BA4EC), + contentPadding: const EdgeInsets.symmetric( + vertical: 5, horizontal: 16), ); }), ], @@ -203,43 +216,47 @@ class _WelcomeScreenState extends State { padding: const EdgeInsets.only(top: 200), child: Row( children: [ - SizedBox(width: 10), + const SizedBox(width: 10), ElevatedButton( onPressed: () { AuthenticationRepository.instance.logout(); }, - child: Icon( + 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, ), - style: ElevatedButton.styleFrom( - primary: Colors.white, - shape: CircleBorder(), - elevation: 3, - minimumSize: Size(45, 45), - ), ), - SizedBox(width: 5), + const SizedBox(width: 5), ElevatedButton( onPressed: () { - Navigator.pushNamed(context, '/profesionalProfile'); + if (state == 'pendiente') { + Navigator.pushNamed(context, '/profesionalProfile'); + } else if (state == 'revision') { + Navigator.pushNamed(context, '/profesionalRevision'); + } }, - child: Text( + style: ElevatedButton.styleFrom( + backgroundColor: const Color(0xFF2BA4EC), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(50), + ), + elevation: 0, + minimumSize: const Size(200, 45), + ), + child: const Text( 'Modo profesional', style: TextStyle( color: Colors.white, fontSize: 15, ), ), - style: ElevatedButton.styleFrom( - primary: Color(0xFF2BA4EC), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(50), - ), - elevation: 0, - minimumSize: Size(200, 45), - ), ), ], ), @@ -248,7 +265,7 @@ class _WelcomeScreenState extends State { ), ), resizeToAvoidBottomInset: false, - backgroundColor: Color(0xFFD6F4FF), + backgroundColor: const Color(0xFFD6F4FF), body: Stack( children: [ Container( @@ -270,12 +287,12 @@ class _WelcomeScreenState extends State { Builder( builder: (context) => ElevatedButton( style: ElevatedButton.styleFrom( - primary: Colors.white, - shape: CircleBorder(), + backgroundColor: Colors.white, + shape: const CircleBorder(), elevation: 3, - minimumSize: Size(50, 50), + minimumSize: const Size(50, 50), ), - child: Icon( + child: const Icon( Icons.menu, color: Colors.black, size: 30, @@ -285,12 +302,12 @@ class _WelcomeScreenState extends State { }, ), ), - SizedBox( + const SizedBox( width: 150, ), - Padding( - padding: const EdgeInsets.only(top: 50), - child: const Image( + const Padding( + padding: EdgeInsets.only(top: 50), + child: Image( image: AssetImage('images/logo_prosapp.png'), width: 120, height: 50, @@ -303,7 +320,7 @@ class _WelcomeScreenState extends State { Container( padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 20), margin: const EdgeInsets.only(top: 170), - child: Align( + child: const Align( alignment: Alignment.topCenter, child: Text( 'Bienvenido', @@ -323,15 +340,16 @@ class _WelcomeScreenState extends State { padding: const EdgeInsets.only(bottom: 40), child: Center( child: ElevatedButton( - onPressed: () { - // AuthenticationRepository.instance.addNameAndEmail( - // uid, - // controller.name.text.trim(), - // controller.email.text.trim(), - // controller.city.text.trim(), - // ); - }, - child: Text( + onPressed: () {}, + style: ElevatedButton.styleFrom( + backgroundColor: const Color(0xFF2BA4EC), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(50), + ), + elevation: 0, + minimumSize: const Size(260, 60), + ), + child: const Text( 'Solicitar un servicio', style: TextStyle( color: Colors.white, @@ -339,14 +357,6 @@ class _WelcomeScreenState extends State { fontSize: 18, ), ), - style: ElevatedButton.styleFrom( - primary: Color(0xFF2BA4EC), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(50), - ), - elevation: 0, - minimumSize: Size(260, 60), - ), )), ), ]),