fix
This commit is contained in:
+107
-39
@@ -330,46 +330,30 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: const Text('Actualizar Email'),
|
title: const Text('Actualizar Email'),
|
||||||
content: Column(
|
content: const Text(
|
||||||
mainAxisSize: MainAxisSize.min,
|
'¿Recuerda primero volver a iniciar sesión para confirmar tu identidad .'),
|
||||||
children: [
|
actions: [
|
||||||
TextFormField(
|
TextButton(
|
||||||
controller: emailController,
|
onPressed: () {
|
||||||
decoration: const InputDecoration(
|
Navigator.of(context).pop();
|
||||||
labelText: 'Nuevo Email',
|
},
|
||||||
),
|
child: const Text('Cancelar'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
String newEmail = emailController.text.trim();
|
||||||
|
if (newEmail.isNotEmpty) {
|
||||||
|
_updateEmail(newEmail);
|
||||||
|
}
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: const Text(
|
||||||
|
'Guardar',
|
||||||
|
style:
|
||||||
|
TextStyle(color: Colors.red, fontWeight: FontWeight.w600),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16.0),
|
),
|
||||||
Row(
|
],
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.grey,
|
|
||||||
),
|
|
||||||
child: const Text('Cancelar'),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
// Llama a una función para actualizar el correo electrónico.
|
|
||||||
String newEmail = emailController.text.trim();
|
|
||||||
if (newEmail.isNotEmpty) {
|
|
||||||
_updateEmail(newEmail);
|
|
||||||
}
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.blue,
|
|
||||||
),
|
|
||||||
child: const Text('Guardar'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -392,6 +376,67 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> deleteAccount() async {
|
||||||
|
try {
|
||||||
|
final currentUser = _auth.currentUser;
|
||||||
|
|
||||||
|
if (currentUser != null) {
|
||||||
|
final uid = currentUser.uid;
|
||||||
|
|
||||||
|
await FirebaseFirestore.instance.collection('users').doc(uid).delete();
|
||||||
|
|
||||||
|
await currentUser.delete();
|
||||||
|
|
||||||
|
await _auth.signOut();
|
||||||
|
|
||||||
|
Get.snackbar(
|
||||||
|
'Cuenta Eliminada',
|
||||||
|
'Tu cuenta ha sido eliminada con éxito.',
|
||||||
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
Get.snackbar(
|
||||||
|
'Error al Eliminar Cuenta',
|
||||||
|
'Hubo un error al eliminar tu cuenta. Por favor, inténtalo de nuevo más tarde.',
|
||||||
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _showDeleteAccountConfirmationDialog(
|
||||||
|
BuildContext context) async {
|
||||||
|
return showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Eliminar Cuenta'),
|
||||||
|
content: const Text(
|
||||||
|
'¿Estás seguro de que deseas eliminar tu cuenta? Esta acción no se puede deshacer.'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: const Text('Cancelar'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
deleteAccount();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: const Text(
|
||||||
|
'Eliminar',
|
||||||
|
style:
|
||||||
|
TextStyle(color: Colors.red, fontWeight: FontWeight.w600),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _showChoiceDialog(BuildContext context) async {
|
Future<void> _showChoiceDialog(BuildContext context) async {
|
||||||
return showDialog(
|
return showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -630,6 +675,29 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 15),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
_showDeleteAccountConfirmationDialog(context);
|
||||||
|
},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor:
|
||||||
|
Colors.red, // Puedes elegir un color adecuado
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(50),
|
||||||
|
),
|
||||||
|
elevation: 0,
|
||||||
|
minimumSize: const Size(300, 45),
|
||||||
|
),
|
||||||
|
child: const Text(
|
||||||
|
'Eliminar Cuenta',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 17,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 40),
|
const SizedBox(height: 40),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
|||||||
@@ -253,6 +253,67 @@ class _ProfileWebScreenState extends State<ProfileWebScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> deleteAccount() async {
|
||||||
|
try {
|
||||||
|
final currentUser = _auth.currentUser;
|
||||||
|
|
||||||
|
if (currentUser != null) {
|
||||||
|
final uid = currentUser.uid;
|
||||||
|
|
||||||
|
await FirebaseFirestore.instance.collection('users').doc(uid).delete();
|
||||||
|
|
||||||
|
await currentUser.delete();
|
||||||
|
|
||||||
|
await _auth.signOut();
|
||||||
|
|
||||||
|
Get.snackbar(
|
||||||
|
'Cuenta Eliminada',
|
||||||
|
'Tu cuenta ha sido eliminada con éxito.',
|
||||||
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
Get.snackbar(
|
||||||
|
'Error al Eliminar Cuenta',
|
||||||
|
'Hubo un error al eliminar tu cuenta. Por favor, inténtalo de nuevo más tarde.',
|
||||||
|
snackPosition: SnackPosition.BOTTOM,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _showDeleteAccountConfirmationDialog(
|
||||||
|
BuildContext context) async {
|
||||||
|
return showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Eliminar Cuenta'),
|
||||||
|
content: const Text(
|
||||||
|
'¿Estás seguro de que deseas eliminar tu cuenta? Esta acción no se puede deshacer.'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: const Text('Cancelar'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
deleteAccount();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: const Text(
|
||||||
|
'Eliminar',
|
||||||
|
style:
|
||||||
|
TextStyle(color: Colors.red, fontWeight: FontWeight.w600),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> updateEmailAndPassword(String email, String password) async {
|
Future<void> updateEmailAndPassword(String email, String password) async {
|
||||||
final User? user = FirebaseAuth.instance.currentUser;
|
final User? user = FirebaseAuth.instance.currentUser;
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
@@ -388,7 +449,7 @@ class _ProfileWebScreenState extends State<ProfileWebScreen> {
|
|||||||
body: Center(
|
body: Center(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 300,
|
width: 300,
|
||||||
height: 600,
|
height: 680,
|
||||||
child: Card(
|
child: Card(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
@@ -579,6 +640,29 @@ class _ProfileWebScreenState extends State<ProfileWebScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 15),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
_showDeleteAccountConfirmationDialog(context);
|
||||||
|
},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor:
|
||||||
|
Colors.red, // Puedes elegir un color adecuado
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(50),
|
||||||
|
),
|
||||||
|
elevation: 0,
|
||||||
|
minimumSize: const Size(300, 45),
|
||||||
|
),
|
||||||
|
child: const Text(
|
||||||
|
'Eliminar Cuenta',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 17,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 40),
|
const SizedBox(height: 40),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
|||||||
Reference in New Issue
Block a user