continuar a team_page
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/team_model.dart';
|
||||
|
||||
class StatsHeader extends StatelessWidget {
|
||||
final Team team;
|
||||
const StatsHeader({super.key, required this.team});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.only(top: 50, left: 16, right: 16, bottom: 25),
|
||||
decoration: const BoxDecoration(color: Color(0xFF2196F3)),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
_buildLogo(),
|
||||
const SizedBox(width: 16),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(team.name, style: const TextStyle(color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold)),
|
||||
Text("Temporada ${team.season}", style: const TextStyle(color: Colors.white70, fontSize: 14)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLogo() {
|
||||
return Container(
|
||||
width: 60, height: 60,
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(12)),
|
||||
child: Center(
|
||||
child: team.imageUrl.startsWith('http')
|
||||
? ClipRRect(borderRadius: BorderRadius.circular(12), child: Image.network(team.imageUrl))
|
||||
: Text(team.imageUrl.isEmpty ? "🏀" : team.imageUrl, style: const TextStyle(fontSize: 30)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SummaryCard extends StatelessWidget {
|
||||
const SummaryCard({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)],
|
||||
),
|
||||
child: const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_StatItem(label: "Jogos", value: "0", color: Colors.black),
|
||||
_StatItem(label: "Vitórias", value: "0", color: Colors.green),
|
||||
_StatItem(label: "Derrotas", value: "0", color: Colors.red),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StatItem extends StatelessWidget {
|
||||
final String label, value;
|
||||
final Color color;
|
||||
const _StatItem({required this.label, required this.value, required this.color});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Text(value, style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold, color: color)),
|
||||
Text(label, style: const TextStyle(color: Colors.grey, fontSize: 13)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:playmaker/screens/team_stats_page.dart';
|
||||
import '../models/team_model.dart';
|
||||
import '../controllers/team_controllers.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; // Recebe o controlador por parâmetro
|
||||
final TeamController controller;
|
||||
|
||||
const TeamCard({
|
||||
super.key,
|
||||
required this.team,
|
||||
required this.controller,
|
||||
|
||||
});
|
||||
|
||||
@override
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
elevation: 3,
|
||||
@@ -23,85 +22,87 @@ class TeamCard extends StatelessWidget {
|
||||
child: ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
|
||||
// 1. LEADING (Lado Esquerdo): Logótipo ou Emoji
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: Colors.grey[200],
|
||||
backgroundImage: (team.imageUrl.startsWith('http'))
|
||||
? NetworkImage(team.imageUrl)
|
||||
: null,
|
||||
child: (!team.imageUrl.startsWith('http'))
|
||||
? Text(
|
||||
team.imageUrl.isEmpty ? "🏀" : team.imageUrl,
|
||||
style: const TextStyle(fontSize: 20),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
|
||||
// 2. TÍTULO E SUBTÍTULO (Centro)
|
||||
title: Text(
|
||||
team.name,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
// Dentro do build do teu TeamCard, no subtitle:
|
||||
subtitle: Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Row(
|
||||
children: [
|
||||
// 1. JOGADORES (À ESQUERDA)
|
||||
const Icon(Icons.groups, size: 16, color: Colors.grey),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
"${team.playerCount} Jogadores",
|
||||
style: TextStyle(
|
||||
color: team.playerCount == 0 ? Colors.orange : Colors.green,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
|
||||
// SEPARADOR VISUAL
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Text("•", style: TextStyle(color: Colors.grey, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
|
||||
// 2. TEMPORADA (A SEGUIR)
|
||||
Text("${team.season} Temporada",
|
||||
style: const TextStyle(
|
||||
color: Colors.grey,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
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,
|
||||
),
|
||||
|
||||
// 3. TRAILING (Lado Direito): Botões de Status e Eliminar
|
||||
// 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: 90, // Espaço fixo para os dois ícones não quebrarem a linha
|
||||
width: 96, // Espaço suficiente para 2 botões
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
// Botão Status
|
||||
// --- BOTÃO DE STATUS (STATS) ---
|
||||
IconButton(
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(),
|
||||
icon: const Icon(Icons.bar_chart, color: Colors.blue),
|
||||
onPressed: () {
|
||||
// NAVEGAÇÃO PARA A NOVA PÁGINA
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TeamStatsPage(team: team),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// Botão Eliminar
|
||||
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(
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(),
|
||||
tooltip: 'Eliminar Equipa',
|
||||
icon: const Icon(Icons.delete_outline, color: Color(0xFFE74C3C)),
|
||||
onPressed: () => _confirmDelete(context),
|
||||
),
|
||||
@@ -117,19 +118,16 @@ subtitle: Padding(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Eliminar Equipa?'),
|
||||
content: Text('Tens a certeza que queres eliminar "${team.name}"? Esta ação não pode ser desfeita.'),
|
||||
content: Text('Tens a certeza que queres eliminar "${team.name}"?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancelar'),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancelar')
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
controller.deleteTeam(team.id);
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text("Equipa eliminada com sucesso")),
|
||||
);
|
||||
},
|
||||
child: const Text('Eliminar', style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
@@ -139,7 +137,7 @@ subtitle: Padding(
|
||||
}
|
||||
}
|
||||
|
||||
// --- WIDGET DO POPUP (CREATE TEAM DIALOG) ---
|
||||
// (O CreateTeamDialog mantém-se igual ao que já tens)
|
||||
class CreateTeamDialog extends StatefulWidget {
|
||||
final Function(String name, String season, String imageUrl) onConfirm;
|
||||
|
||||
@@ -165,42 +163,42 @@ class _CreateTeamDialogState extends State<CreateTeamDialog> {
|
||||
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) {
|
||||
return DropdownMenuItem(value: s, child: Text(s));
|
||||
}).toList(),
|
||||
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 do Logótipo ou Emoji',
|
||||
hintText: 'Ex: 🏀 ou link http',
|
||||
labelText: 'URL Imagem ou Emoji',
|
||||
hintText: 'Ex: 🏀 ou https://...',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: const Text('Cancelar')),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFFE74C3C)),
|
||||
onPressed: () {
|
||||
widget.onConfirm(
|
||||
_nameController.text,
|
||||
_selectedSeason,
|
||||
_imageController.text
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
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)),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user