update y uso de provider
This commit is contained in:
@@ -1,11 +1,88 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||
import 'package:prosappco/src/screens/about.dart';
|
||||
|
||||
class ConfiguracionScreen extends StatelessWidget {
|
||||
class ConfiguracionScreen extends StatefulWidget {
|
||||
const ConfiguracionScreen({super.key});
|
||||
|
||||
@override
|
||||
State<ConfiguracionScreen> createState() => _ConfiguracionScreenState();
|
||||
}
|
||||
|
||||
class _ConfiguracionScreenState extends State<ConfiguracionScreen> {
|
||||
late final FirebaseAuth _auth;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_auth = FirebaseAuth.instance;
|
||||
}
|
||||
|
||||
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),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -14,22 +91,35 @@ class ConfiguracionScreen extends StatelessWidget {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
label: 'Configuración'),
|
||||
body: ListTile(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return const AboutScreen();
|
||||
},
|
||||
body: ListView(
|
||||
children: [
|
||||
ListTile(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return const AboutScreen();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
title: const Text('Acerca de la aplicación'),
|
||||
trailing: const Icon(
|
||||
Icons.keyboard_arrow_right,
|
||||
color: Colors.black,
|
||||
),
|
||||
);
|
||||
},
|
||||
title: const Text('Acerca de la aplicación'),
|
||||
trailing: const Icon(
|
||||
Icons.keyboard_arrow_right,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () {
|
||||
_showDeleteAccountConfirmationDialog(context);
|
||||
},
|
||||
title: const Text(
|
||||
'Eliminar cuenta',
|
||||
style: TextStyle(color: Colors.red),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,11 +9,12 @@ import 'package:intl/intl.dart';
|
||||
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||
import 'package:prosappco/src/controllers/add_name_email_city.dart';
|
||||
import 'package:prosappco/src/providers/user_provider.dart';
|
||||
import 'package:prosappco/src/screens/city.dart';
|
||||
import 'package:prosappco/src/screens/new_number.dart';
|
||||
import 'package:prosappco/src/screens/new_password.dart';
|
||||
import 'package:prosappco/src/services/select_image_profile.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
import '../components/photo_view.dart';
|
||||
|
||||
class ProfileScreen extends StatefulWidget {
|
||||
@@ -293,6 +294,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
} catch (e) {
|
||||
print('Error al actualizar la imagen de perfil $e');
|
||||
}
|
||||
|
||||
// notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _updateEmail(String newEmail) async {
|
||||
@@ -376,67 +379,6 @@ 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 {
|
||||
return showDialog(
|
||||
context: context,
|
||||
@@ -484,6 +426,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final userProvider = Provider.of<UserProvider>(context);
|
||||
String city = _ciudad.toString();
|
||||
|
||||
return Scaffold(
|
||||
@@ -675,30 +618,6 @@ 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),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
|
||||
@@ -252,7 +252,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
|
||||
setState(() {
|
||||
appVersion = version;
|
||||
print('Version de app $appVersion - version de firebase $settings');
|
||||
// print('Version de app $appVersion - version de firebase $settings');
|
||||
});
|
||||
|
||||
if (settings != null) {
|
||||
|
||||
Reference in New Issue
Block a user