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