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