meter firebase

This commit is contained in:
2026-01-14 10:40:31 +00:00
parent fc527084de
commit 01d5e7adb6
2 changed files with 143 additions and 24 deletions

View File

@@ -29,6 +29,61 @@ class StatsController {
.map((doc) => Person.fromFirestore(doc.data(), doc.id))
.toList());
}
// --- Adiciona estas funções dentro da classe StatsController ---
// ELIMINAR: Remove o documento da sub-coleção
Future<void> deletePerson(String teamId, String personId) async {
await _db
.collection('teams')
.doc(teamId)
.collection('members')
.doc(personId)
.delete();
}
// EDITAR (LOGICA): Abre o popup já preenchido com os dados atuais
void showEditPersonDialog(BuildContext context, String teamId, Person person) {
final nameController = TextEditingController(text: person.name);
final numberController = TextEditingController(text: person.number);
String selectedType = person.type;
showDialog(
context: context,
builder: (context) => StatefulBuilder(
builder: (context, setPopupState) => AlertDialog(
title: const Text("Editar Personagem"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
DropdownButtonFormField<String>(
value: selectedType,
items: ['Jogador', 'Treinador'].map((t) => DropdownMenuItem(value: t, child: Text(t))).toList(),
onChanged: (val) => setPopupState(() => selectedType = val!),
decoration: const InputDecoration(labelText: 'Tipo'),
),
TextField(controller: nameController, decoration: const InputDecoration(labelText: 'Nome')),
if (selectedType == 'Jogador')
TextField(controller: numberController, decoration: const InputDecoration(labelText: 'Número')),
],
),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text("Cancelar")),
ElevatedButton(
onPressed: () async {
await _db.collection('teams').doc(teamId).collection('members').doc(person.id).update({
'name': nameController.text,
'type': selectedType,
'number': selectedType == 'Jogador' ? numberController.text : '',
});
if (context.mounted) Navigator.pop(context);
},
child: const Text("Guardar Alterações"),
),
],
),
),
);
}
// --- LÓGICA DE INTERFACE (POPUP) ---