update
This commit is contained in:
@@ -377,6 +377,8 @@ class DrawerMenu extends StatelessWidget {
|
|||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
AuthenticationRepository.instance.logout(uid!);
|
AuthenticationRepository.instance.logout(uid!);
|
||||||
|
|
||||||
|
userProvider.initUserProvider();
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.red,
|
||||||
|
|||||||
@@ -40,7 +40,9 @@ class _ProfessionScreenState extends State<ProfessionScreen> {
|
|||||||
TextEditingController searchController = TextEditingController();
|
TextEditingController searchController = TextEditingController();
|
||||||
final User? user = FirebaseAuth.instance.currentUser;
|
final User? user = FirebaseAuth.instance.currentUser;
|
||||||
List<String>? _professions;
|
List<String>? _professions;
|
||||||
|
final ScrollController _scrollController = ScrollController();
|
||||||
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||||
|
bool isNewProfessionAdded = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (filteredProfessions == null) {
|
if (filteredProfessions == null) {
|
||||||
@@ -113,18 +162,38 @@ class _ProfessionScreenState extends State<ProfessionScreen> {
|
|||||||
children: [
|
children: [
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// Aquí puedes agregar la navegación a la vista deseada
|
String newProfession = "";
|
||||||
Navigator.push(
|
|
||||||
context,
|
showDialog(
|
||||||
MaterialPageRoute(
|
context: context,
|
||||||
builder: (context) =>
|
builder: (context) {
|
||||||
const SupportScreen()), // Reemplaza "OtraVista()" con el nombre de tu vista
|
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(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(10),
|
padding: const EdgeInsets.all(10),
|
||||||
child: const Text(
|
child: const Text(
|
||||||
'Si tu profesión no aparece, haz clic aquí',
|
'Si tu profesión no aparece, presiona aquí',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16.0,
|
fontSize: 16.0,
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
@@ -145,16 +214,24 @@ class _ProfessionScreenState extends State<ProfessionScreen> {
|
|||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
|
controller: _scrollController,
|
||||||
itemCount: professions.length,
|
itemCount: professions.length,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
professions[index],
|
professions[index],
|
||||||
style: const TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 18.0,
|
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: () {
|
onTap: () {
|
||||||
updateProfession(professions[index]);
|
updateProfession(professions[index]);
|
||||||
Navigator.pop(context, professions[index]);
|
Navigator.pop(context, professions[index]);
|
||||||
|
|||||||
Reference in New Issue
Block a user