This commit is contained in:
Felipe
2023-11-01 15:33:55 -05:00
parent 70bdfd28ec
commit 1751acd02f
2 changed files with 88 additions and 9 deletions
+2
View File
@@ -377,6 +377,8 @@ class DrawerMenu extends StatelessWidget {
ElevatedButton(
onPressed: () {
AuthenticationRepository.instance.logout(uid!);
userProvider.initUserProvider();
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
+86 -9
View File
@@ -40,7 +40,9 @@ class _ProfessionScreenState extends State<ProfessionScreen> {
TextEditingController searchController = TextEditingController();
final User? user = FirebaseAuth.instance.currentUser;
List<String>? _professions;
final ScrollController _scrollController = ScrollController();
final uid = AuthenticationRepository.instance.getCurrentUserUid();
bool isNewProfessionAdded = false;
@override
void initState() {
@@ -90,6 +92,53 @@ class _ProfessionScreenState extends State<ProfessionScreen> {
}
}
Future<void> saveProfession(String newProfession) async {
final DocumentReference professionsDocRef =
professionsCollection.doc('professions');
try {
final DocumentSnapshot<Object?> profession =
await professionsDocRef.get();
Map<String, dynamic> data = profession.data() as Map<String, dynamic>;
List<String> professions = [];
if (data['professions'] != null) {
professions = List<String>.from(data['professions']);
}
professions.add(newProfession);
await professionsDocRef.set({
'professions': professions,
}, SetOptions(merge: true));
setState(() {
getProfessions().then((List<String> element) => setState(() {
_professions = element;
filteredProfessions = element;
int newIndex = professions.indexOf(newProfession);
if (newIndex != -1) {
_scrollController.animateTo(
newIndex * 50.0,
duration: const Duration(milliseconds: 600),
curve: Curves.easeIn,
);
}
isNewProfessionAdded = true;
Future.delayed(const Duration(seconds: 2), () {
setState(() {
isNewProfessionAdded = false;
});
});
}));
});
} catch (e) {
print('Error al guardar la profesión: $e');
}
}
@override
Widget build(BuildContext context) {
if (filteredProfessions == null) {
@@ -113,18 +162,38 @@ class _ProfessionScreenState extends State<ProfessionScreen> {
children: [
GestureDetector(
onTap: () {
// Aquí puedes agregar la navegación a la vista deseada
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const SupportScreen()), // Reemplaza "OtraVista()" con el nombre de tu vista
String newProfession = "";
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text("Agregar una profesión"),
content: TextField(
controller: TextEditingController(),
onChanged: (value) {
newProfession = value;
},
),
actions: [
ElevatedButton(
onPressed: () {
if (newProfession.isNotEmpty) {
saveProfession(newProfession);
Navigator.pop(context);
}
},
child: const Text("Guardar"),
),
],
);
},
);
},
child: Container(
padding: const EdgeInsets.all(10),
child: const Text(
'Si tu profesión no aparece, haz clic aquí',
'Si tu profesión no aparece, presiona aquí',
style: TextStyle(
fontSize: 16.0,
color: Colors.blue,
@@ -145,16 +214,24 @@ class _ProfessionScreenState extends State<ProfessionScreen> {
),
Expanded(
child: ListView.builder(
controller: _scrollController,
itemCount: professions.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(
professions[index],
style: const TextStyle(
style: TextStyle(
fontSize: 18.0,
color: Colors.black,
color: isNewProfessionAdded &&
index == professions.length - 1
? Colors.white
: Colors.black,
),
),
tileColor:
isNewProfessionAdded && index == professions.length - 1
? Colors.blue
: null,
onTap: () {
updateProfession(professions[index]);
Navigator.pop(context, professions[index]);