update
This commit is contained in:
@@ -219,7 +219,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
String newPassword = _passwordController.text.trim();
|
||||
|
||||
if (newName.isEmpty) {
|
||||
// Si el nuevo nombre está vacío, no lo actualizamos y mostramos un mensaje al usuario
|
||||
Get.snackbar(
|
||||
'Nombre Invalido',
|
||||
'Ingresa un nombre válido.',
|
||||
@@ -229,7 +228,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
}
|
||||
|
||||
if (newEmail.isEmpty) {
|
||||
// Si el nuevo email está vacío, no lo actualizamos y mostramos un mensaje al usuario
|
||||
Get.snackbar(
|
||||
'Correo Invalido',
|
||||
'Ingresa un email válido.',
|
||||
@@ -298,27 +296,70 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
// notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _updateEmail(String newEmail) async {
|
||||
Future<void> _updateEmailAndPassword(
|
||||
String newEmail, String currentPassword) async {
|
||||
final user = _auth.currentUser;
|
||||
|
||||
if (user!.email! == newEmail) {
|
||||
Get.snackbar(
|
||||
'No se puede actualizar',
|
||||
'El correo actual no puede ser actualizado.',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!newEmail.contains('@') || !newEmail.contains('.')) {
|
||||
Get.snackbar(
|
||||
'No se puede actualizar',
|
||||
'Ingresa un correo electrónico valido.',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
final emailExistsQuery = await FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.where('email', isEqualTo: newEmail)
|
||||
.get();
|
||||
|
||||
if (emailExistsQuery.docs.isNotEmpty) {
|
||||
Get.snackbar(
|
||||
'No se puede actualizar',
|
||||
'El nuevo correo electrónico ya está en uso.',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await user!.updateEmail(newEmail);
|
||||
final credential = EmailAuthProvider.credential(
|
||||
email: user.email!, password: currentPassword);
|
||||
await user.reauthenticateWithCredential(credential);
|
||||
|
||||
await user.updateEmail(newEmail);
|
||||
|
||||
await FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'email': newEmail});
|
||||
|
||||
setState(() {
|
||||
_email = newEmail;
|
||||
});
|
||||
|
||||
Get.snackbar(
|
||||
'Éxito',
|
||||
'Correo electrónico actualizado correctamente.',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
|
||||
Navigator.of(context).pop();
|
||||
} catch (e) {
|
||||
Get.snackbar(
|
||||
'No se pudo actualizar el correo',
|
||||
'Primero vuelve a iniciar sesión para confirmar tu identidad y asegurarte de que el nuevo correo electrónico no se haya utilizado previamente.',
|
||||
'Verifica tu contraseña actual y asegúrate de que el nuevo correo electrónico no se haya utilizado previamente.',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
print('Error al actualizar el correo electrónico: $e');
|
||||
@@ -327,33 +368,50 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
|
||||
Future<void> _showEmailUpdateDialog(BuildContext context) async {
|
||||
TextEditingController emailController = TextEditingController();
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Actualizar Email'),
|
||||
content: const Text(
|
||||
'¿Recuerda primero volver a iniciar sesión para confirmar tu identidad .'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: emailController,
|
||||
decoration: const InputDecoration(labelText: 'Nuevo Email'),
|
||||
),
|
||||
TextField(
|
||||
controller: passwordController,
|
||||
decoration:
|
||||
const InputDecoration(labelText: 'Contraseña Actual'),
|
||||
obscureText: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text('Cancelar'),
|
||||
child: const Text(
|
||||
'Cancelar',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
String newEmail = emailController.text.trim();
|
||||
if (newEmail.isNotEmpty) {
|
||||
_updateEmail(newEmail);
|
||||
String currentPassword = passwordController.text.trim();
|
||||
if (newEmail.isNotEmpty && currentPassword.isNotEmpty) {
|
||||
_updateEmailAndPassword(newEmail, currentPassword);
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text(
|
||||
'Guardar',
|
||||
style:
|
||||
TextStyle(color: Colors.red, fontWeight: FontWeight.w600),
|
||||
TextStyle(color: Colors.blue, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -619,7 +677,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
),
|
||||
),
|
||||
)
|
||||
: SizedBox(height: 20),
|
||||
: const SizedBox(height: 20),
|
||||
const SizedBox(height: 60),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
|
||||
@@ -15,7 +15,6 @@ import 'package:prosappco/src/components/drawer_menu.dart';
|
||||
import 'package:prosappco/src/models/event_model.dart';
|
||||
import 'package:prosappco/src/models/setting_model.dart';
|
||||
import 'package:prosappco/src/models/user_model.dart';
|
||||
import 'package:prosappco/src/providers/user_provider.dart';
|
||||
import 'package:prosappco/src/screens/professional.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:prosappco/src/screens/profile.dart';
|
||||
@@ -26,7 +25,6 @@ import 'package:prosappco/src/screens/ubicacion.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:prosappco/src/components/network_utility.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class ServiceScreen extends StatefulWidget {
|
||||
@@ -113,7 +111,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
DateTime? _selectedDate;
|
||||
TimeOfDay? _selectedTime;
|
||||
|
||||
late GoogleMapController googleMapController;
|
||||
GoogleMapController? googleMapController;
|
||||
|
||||
Set<Marker> markers = {};
|
||||
|
||||
@@ -211,7 +209,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
double lat = double.parse(coords[0]);
|
||||
double lng = double.parse(coords[1]);
|
||||
|
||||
googleMapController.moveCamera(
|
||||
googleMapController?.moveCamera(
|
||||
CameraUpdate.newLatLngZoom(
|
||||
LatLng(lat, lng),
|
||||
14.4746,
|
||||
@@ -221,7 +219,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
try {
|
||||
Position position = await _determinePosition();
|
||||
|
||||
googleMapController.animateCamera(
|
||||
googleMapController?.animateCamera(
|
||||
CameraUpdate.newCameraPosition(
|
||||
CameraPosition(
|
||||
target: LatLng(
|
||||
@@ -743,7 +741,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
zoomControlsEnabled: false,
|
||||
onMapCreated: (GoogleMapController controller) {
|
||||
googleMapController = controller;
|
||||
googleMapController.setMapStyle('''
|
||||
googleMapController?.setMapStyle('''
|
||||
[
|
||||
{
|
||||
"elementType": "labels.icon",
|
||||
@@ -862,7 +860,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
try {
|
||||
Position position = await _determinePosition();
|
||||
|
||||
googleMapController.animateCamera(
|
||||
googleMapController?.animateCamera(
|
||||
CameraUpdate.newCameraPosition(
|
||||
CameraPosition(
|
||||
target: LatLng(
|
||||
@@ -1018,7 +1016,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
null &&
|
||||
professionalLongitude != 0) {
|
||||
googleMapController
|
||||
.animateCamera(
|
||||
?.animateCamera(
|
||||
CameraUpdate
|
||||
.newCameraPosition(
|
||||
CameraPosition(
|
||||
@@ -1082,7 +1080,8 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
final newCoordinates = LatLng(
|
||||
selectedLatitude,
|
||||
selectedLongitude);
|
||||
googleMapController.animateCamera(
|
||||
googleMapController
|
||||
?.animateCamera(
|
||||
CameraUpdate.newLatLng(
|
||||
newCoordinates),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user