ver se a parte de eliminar fica com botao ou arrastar perguntar ao setor meter emolador de tabelet ou phone

This commit is contained in:
2026-01-28 12:34:30 +00:00
parent dc3a9723a4
commit 2fdb0a62d8
4 changed files with 307 additions and 111 deletions

View File

@@ -1,65 +1,91 @@
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;
final VoidCallback onFavoriteTap;
const TeamCard({
super.key,
required this.team,
super.key,
required this.team,
required this.controller,
required this.onFavoriteTap,
});
@override
@override
Widget build(BuildContext context) {
return Card(
color: Colors.white,
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
leading: Stack(
clipBehavior: Clip.none, // Permite que a estrela flutue ligeiramente fora do círculo
children: [
// 1. IMAGEM DA EQUIPA
CircleAvatar(
radius: 28,
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: 24),
)
: null,
),
// 2. BOTÃO DA ESTRELA (Favorito)
Positioned(
left: -15, // Posiciona à esquerda da imagem
top: -10,
child: IconButton(
// O segredo está em colocar o shadow dentro do Icon:
icon: Icon(
team.isFavorite ? Icons.star : Icons.star_border,
color: team.isFavorite ? Colors.amber : Colors.black.withOpacity(0.1), // Transparente se não favorito
size: 28,
shadows: [
Shadow(
color: Colors.black.withOpacity(team.isFavorite ? 0.3 : 0.1),
blurRadius: 4,
),
],
),
onPressed: onFavoriteTap,
),
),
],
),
// --- NOME DA EQUIPA ---
title: Text(
team.name,
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
// 3. SUBTÍTULO (CONTAGEM DE JOGADORES)
// --- SUBTÍTULO (CONTAGEM E TEMPORADA) ---
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,
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,
@@ -67,31 +93,26 @@ class TeamCard extends StatelessWidget {
);
},
),
const SizedBox(width: 10),
// Temporada
Text(
"| ${team.season}",
"| ${team.season}",
style: const TextStyle(color: Colors.grey, fontSize: 13),
),
],
),
),
// 4. BOTÕES DE AÇÃO (Lado Direito)
// --- BOTÕES DE ACÇÃO À DIREITA ---
trailing: SizedBox(
width: 96, // Espaço suficiente para 2 botões
width: 80,
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(
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TeamStatsPage(team: team),
@@ -99,8 +120,6 @@ class TeamCard extends StatelessWidget {
);
},
),
// --- BOTÃO ELIMINAR ---
IconButton(
tooltip: 'Eliminar Equipa',
icon: const Icon(Icons.delete_outline, color: Color(0xFFE74C3C)),
@@ -112,7 +131,6 @@ class TeamCard extends StatelessWidget {
),
);
}
void _confirmDelete(BuildContext context) {
showDialog(
context: context,
@@ -129,15 +147,14 @@ class TeamCard extends StatelessWidget {
controller.deleteTeam(team.id);
Navigator.pop(context);
},
child: const Text('Eliminar', style: TextStyle(color: Colors.red)),
),
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;
@@ -194,7 +211,7 @@ onPressed: () {
widget.onConfirm(
_nameController.text.trim(),
_selectedSeason,
_imageController.text.trim() // Trim remove espaços extras
_imageController.text.trim()
);
Navigator.pop(context);
}