update
This commit is contained in:
@@ -219,7 +219,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
String newPassword = _passwordController.text.trim();
|
String newPassword = _passwordController.text.trim();
|
||||||
|
|
||||||
if (newName.isEmpty) {
|
if (newName.isEmpty) {
|
||||||
// Si el nuevo nombre está vacío, no lo actualizamos y mostramos un mensaje al usuario
|
|
||||||
Get.snackbar(
|
Get.snackbar(
|
||||||
'Nombre Invalido',
|
'Nombre Invalido',
|
||||||
'Ingresa un nombre válido.',
|
'Ingresa un nombre válido.',
|
||||||
@@ -229,7 +228,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newEmail.isEmpty) {
|
if (newEmail.isEmpty) {
|
||||||
// Si el nuevo email está vacío, no lo actualizamos y mostramos un mensaje al usuario
|
|
||||||
Get.snackbar(
|
Get.snackbar(
|
||||||
'Correo Invalido',
|
'Correo Invalido',
|
||||||
'Ingresa un email válido.',
|
'Ingresa un email válido.',
|
||||||
@@ -298,27 +296,70 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
// notifyListeners();
|
// notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateEmail(String newEmail) async {
|
Future<void> _updateEmailAndPassword(
|
||||||
|
String newEmail, String currentPassword) async {
|
||||||
final user = _auth.currentUser;
|
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 {
|
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
|
await FirebaseFirestore.instance
|
||||||
.collection('users')
|
.collection('users')
|
||||||
.doc(uid)
|
.doc(uid)
|
||||||
.update({'email': newEmail});
|
.update({'email': newEmail});
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_email = newEmail;
|
_email = newEmail;
|
||||||
});
|
});
|
||||||
|
|
||||||
Get.snackbar(
|
Get.snackbar(
|
||||||
'Éxito',
|
'Éxito',
|
||||||
'Correo electrónico actualizado correctamente.',
|
'Correo electrónico actualizado correctamente.',
|
||||||
snackPosition: SnackPosition.BOTTOM,
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Navigator.of(context).pop();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Get.snackbar(
|
Get.snackbar(
|
||||||
'No se pudo actualizar el correo',
|
'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,
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
);
|
);
|
||||||
print('Error al actualizar el correo electrónico: $e');
|
print('Error al actualizar el correo electrónico: $e');
|
||||||
@@ -327,33 +368,50 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
|
|
||||||
Future<void> _showEmailUpdateDialog(BuildContext context) async {
|
Future<void> _showEmailUpdateDialog(BuildContext context) async {
|
||||||
TextEditingController emailController = TextEditingController();
|
TextEditingController emailController = TextEditingController();
|
||||||
|
TextEditingController passwordController = TextEditingController();
|
||||||
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: const Text('Actualizar Email'),
|
title: const Text('Actualizar Email'),
|
||||||
content: const Text(
|
content: Column(
|
||||||
'¿Recuerda primero volver a iniciar sesión para confirmar tu identidad .'),
|
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: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
child: const Text('Cancelar'),
|
child: const Text(
|
||||||
|
'Cancelar',
|
||||||
|
style: TextStyle(color: Colors.grey),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
String newEmail = emailController.text.trim();
|
String newEmail = emailController.text.trim();
|
||||||
if (newEmail.isNotEmpty) {
|
String currentPassword = passwordController.text.trim();
|
||||||
_updateEmail(newEmail);
|
if (newEmail.isNotEmpty && currentPassword.isNotEmpty) {
|
||||||
|
_updateEmailAndPassword(newEmail, currentPassword);
|
||||||
}
|
}
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
},
|
||||||
child: const Text(
|
child: const Text(
|
||||||
'Guardar',
|
'Guardar',
|
||||||
style:
|
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),
|
const SizedBox(height: 60),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
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/event_model.dart';
|
||||||
import 'package:prosappco/src/models/setting_model.dart';
|
import 'package:prosappco/src/models/setting_model.dart';
|
||||||
import 'package:prosappco/src/models/user_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:prosappco/src/screens/professional.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:prosappco/src/screens/profile.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:http/http.dart' as http;
|
||||||
import 'package:prosappco/src/components/network_utility.dart';
|
import 'package:prosappco/src/components/network_utility.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class ServiceScreen extends StatefulWidget {
|
class ServiceScreen extends StatefulWidget {
|
||||||
@@ -113,7 +111,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
DateTime? _selectedDate;
|
DateTime? _selectedDate;
|
||||||
TimeOfDay? _selectedTime;
|
TimeOfDay? _selectedTime;
|
||||||
|
|
||||||
late GoogleMapController googleMapController;
|
GoogleMapController? googleMapController;
|
||||||
|
|
||||||
Set<Marker> markers = {};
|
Set<Marker> markers = {};
|
||||||
|
|
||||||
@@ -211,7 +209,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
double lat = double.parse(coords[0]);
|
double lat = double.parse(coords[0]);
|
||||||
double lng = double.parse(coords[1]);
|
double lng = double.parse(coords[1]);
|
||||||
|
|
||||||
googleMapController.moveCamera(
|
googleMapController?.moveCamera(
|
||||||
CameraUpdate.newLatLngZoom(
|
CameraUpdate.newLatLngZoom(
|
||||||
LatLng(lat, lng),
|
LatLng(lat, lng),
|
||||||
14.4746,
|
14.4746,
|
||||||
@@ -221,7 +219,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
try {
|
try {
|
||||||
Position position = await _determinePosition();
|
Position position = await _determinePosition();
|
||||||
|
|
||||||
googleMapController.animateCamera(
|
googleMapController?.animateCamera(
|
||||||
CameraUpdate.newCameraPosition(
|
CameraUpdate.newCameraPosition(
|
||||||
CameraPosition(
|
CameraPosition(
|
||||||
target: LatLng(
|
target: LatLng(
|
||||||
@@ -743,7 +741,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
zoomControlsEnabled: false,
|
zoomControlsEnabled: false,
|
||||||
onMapCreated: (GoogleMapController controller) {
|
onMapCreated: (GoogleMapController controller) {
|
||||||
googleMapController = controller;
|
googleMapController = controller;
|
||||||
googleMapController.setMapStyle('''
|
googleMapController?.setMapStyle('''
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"elementType": "labels.icon",
|
"elementType": "labels.icon",
|
||||||
@@ -862,7 +860,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
try {
|
try {
|
||||||
Position position = await _determinePosition();
|
Position position = await _determinePosition();
|
||||||
|
|
||||||
googleMapController.animateCamera(
|
googleMapController?.animateCamera(
|
||||||
CameraUpdate.newCameraPosition(
|
CameraUpdate.newCameraPosition(
|
||||||
CameraPosition(
|
CameraPosition(
|
||||||
target: LatLng(
|
target: LatLng(
|
||||||
@@ -1018,7 +1016,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
null &&
|
null &&
|
||||||
professionalLongitude != 0) {
|
professionalLongitude != 0) {
|
||||||
googleMapController
|
googleMapController
|
||||||
.animateCamera(
|
?.animateCamera(
|
||||||
CameraUpdate
|
CameraUpdate
|
||||||
.newCameraPosition(
|
.newCameraPosition(
|
||||||
CameraPosition(
|
CameraPosition(
|
||||||
@@ -1082,7 +1080,8 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
|||||||
final newCoordinates = LatLng(
|
final newCoordinates = LatLng(
|
||||||
selectedLatitude,
|
selectedLatitude,
|
||||||
selectedLongitude);
|
selectedLongitude);
|
||||||
googleMapController.animateCamera(
|
googleMapController
|
||||||
|
?.animateCamera(
|
||||||
CameraUpdate.newLatLng(
|
CameraUpdate.newLatLng(
|
||||||
newCoordinates),
|
newCoordinates),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user