Files
PlayMaker/lib/widgets/team_widgets.dart
2026-01-27 17:17:31 +00:00

207 lines
6.7 KiB
Dart

import 'package:flutter/material.dart';
import '../models/team_model.dart';
import '../controllers/team_controller.dart';
// Importa a tua página de stats (verifica se o caminho está correto)
import '../screens/team_stats_page.dart';
class TeamCard extends StatelessWidget {
final Team team;
final TeamController controller;
const TeamCard({
super.key,
required this.team,
required this.controller,
});
@override
Widget build(BuildContext context) {
return Card(
elevation: 3,
margin: const EdgeInsets.only(bottom: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
child: ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
leading: CircleAvatar(
backgroundColor: Colors.grey[200],
backgroundImage: (team.imageUrl.isNotEmpty && team.imageUrl.startsWith('http'))
? NetworkImage(team.imageUrl)
: null,
child: (team.imageUrl.isEmpty || !team.imageUrl.startsWith('http'))
? Text(
team.imageUrl.isEmpty ? "🏀" : team.imageUrl,
style: const TextStyle(fontSize: 20),
)
: null,
),
// 2. NOME DA EQUIPA
title: Text(
team.name,
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
// 3. SUBTÍTULO (CONTAGEM DE JOGADORES)
subtitle: Padding(
padding: const EdgeInsets.only(top: 6.0),
child: Row(
children: [
// Ícone de grupo
const Icon(Icons.groups_outlined, size: 16, color: Colors.grey),
const SizedBox(width: 4),
// Contagem assíncrona
FutureBuilder<int>(
future: controller.getPlayerCount(team.id),
initialData: 0,
builder: (context, snapshot) {
final count = snapshot.data ?? 0;
return Text(
"$count Jogadores",
style: TextStyle(
// Verde se tiver jogadores, Laranja se estiver vazio
color: count > 0 ? Colors.green[700] : Colors.orange,
fontWeight: FontWeight.bold,
fontSize: 13,
),
);
},
),
const SizedBox(width: 10),
// Temporada
Text(
"| ${team.season}",
style: const TextStyle(color: Colors.grey, fontSize: 13),
),
],
),
),
// 4. BOTÕES DE AÇÃO (Lado Direito)
trailing: SizedBox(
width: 96, // Espaço suficiente para 2 botões
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
// --- BOTÃO DE STATUS (STATS) ---
IconButton(
tooltip: 'Ver Estatísticas',
icon: const Icon(Icons.bar_chart_rounded, color: Colors.blue),
onPressed: () {
// Navega para a página de gestão da equipa
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TeamStatsPage(team: team),
),
);
},
),
// --- BOTÃO ELIMINAR ---
IconButton(
tooltip: 'Eliminar Equipa',
icon: const Icon(Icons.delete_outline, color: Color(0xFFE74C3C)),
onPressed: () => _confirmDelete(context),
),
],
),
),
),
);
}
void _confirmDelete(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Eliminar Equipa?'),
content: Text('Tens a certeza que queres eliminar "${team.name}"?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancelar')
),
TextButton(
onPressed: () {
controller.deleteTeam(team.id);
Navigator.pop(context);
},
child: const Text('Eliminar', style: TextStyle(color: Colors.red)),
),
],
),
);
}
}
// (O CreateTeamDialog mantém-se igual ao que já tens)
class CreateTeamDialog extends StatefulWidget {
final Function(String name, String season, String imageUrl) onConfirm;
const CreateTeamDialog({super.key, required this.onConfirm});
@override
State<CreateTeamDialog> createState() => _CreateTeamDialogState();
}
class _CreateTeamDialogState extends State<CreateTeamDialog> {
final TextEditingController _nameController = TextEditingController();
final TextEditingController _imageController = TextEditingController();
String _selectedSeason = '2024/25';
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('Nova Equipa'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: _nameController,
decoration: const InputDecoration(labelText: 'Nome da Equipa'),
textCapitalization: TextCapitalization.words,
),
const SizedBox(height: 15),
DropdownButtonFormField<String>(
value: _selectedSeason,
decoration: const InputDecoration(labelText: 'Temporada'),
items: ['2023/24', '2024/25', '2025/26']
.map((s) => DropdownMenuItem(value: s, child: Text(s)))
.toList(),
onChanged: (val) => setState(() => _selectedSeason = val!),
),
const SizedBox(height: 15),
TextField(
controller: _imageController,
decoration: const InputDecoration(
labelText: 'URL Imagem ou Emoji',
hintText: 'Ex: 🏀 ou https://...',
),
),
],
),
),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text('Cancelar')),
ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFFE74C3C)),
onPressed: () {
if (_nameController.text.trim().isNotEmpty) {
widget.onConfirm(
_nameController.text.trim(),
_selectedSeason,
_imageController.text.trim() // Trim remove espaços extras
);
Navigator.pop(context);
}
},
child: const Text('Criar', style: TextStyle(color: Colors.white)),
),
],
);
}
}