This commit is contained in:
2026-02-03 17:33:40 +00:00
parent 2a9661978c
commit 74453f7cbc
22 changed files with 1082 additions and 639 deletions

View File

@@ -0,0 +1,220 @@
import 'package:flutter/material.dart';
import 'package:playmaker/pages/PlacarPage.dart';
import '../controllers/team_controller.dart';
// --- CARD DE EXIBIÇÃO DO JOGO ---
class GameResultCard extends StatelessWidget {
final String gameId; // Adicionado para identificar o jogo no retorno
final String myTeam, opponentTeam, myScore, opponentScore, status, season;
const GameResultCard({
super.key,
required this.gameId,
required this.myTeam,
required this.opponentTeam,
required this.myScore,
required this.opponentScore,
required this.status,
required this.season,
});
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(bottom: 16),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 10)],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_buildTeamInfo(myTeam, const Color(0xFFE74C3C)),
// Agora passamos o context e o gameId para o centro
_buildScoreCenter(context, gameId),
_buildTeamInfo(opponentTeam, Colors.black87),
],
),
);
}
Widget _buildTeamInfo(String name, Color color) {
return Column(
children: [
CircleAvatar(
backgroundColor: color,
child: const Icon(Icons.shield, color: Colors.white)
),
const SizedBox(height: 4),
Text(name, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 12)),
],
);
}
Widget _buildScoreCenter(BuildContext context, String id) {
return Column(
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
_scoreBox(myScore, Colors.green),
const Text(" : ", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20)),
_scoreBox(opponentScore, Colors.grey),
],
),
const SizedBox(height: 8),
// BOTÃO PARA RETORNAR AO JOGO
TextButton.icon(
onPressed: () {
print("Navegando para o marcador do jogo: $id");
// Aqui faremos a navegação para a página do marcador em breve
},
icon: const Icon(Icons.play_circle_fill, size: 16, color: Color(0xFFE74C3C)),
label: const Text(
"RETORNAR",
style: TextStyle(
fontSize: 10,
color: Color(0xFFE74C3C),
fontWeight: FontWeight.bold
),
),
style: TextButton.styleFrom(
backgroundColor: const Color(0xFFE74C3C).withOpacity(0.1),
padding: const EdgeInsets.symmetric(horizontal: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
visualDensity: VisualDensity.compact,
),
),
const SizedBox(height: 4),
Text(status, style: const TextStyle(fontSize: 10, color: Colors.blue, fontWeight: FontWeight.bold)),
],
);
}
Widget _scoreBox(String pts, Color c) => Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(color: c, borderRadius: BorderRadius.circular(8)),
child: Text(pts, style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
);
}
// --- POPUP DE CRIAÇÃO ---
class CreateGameDialogManual extends StatefulWidget {
final TeamController controller;
final Function(String, String, String) onConfirm;
const CreateGameDialogManual({super.key, required this.controller, required this.onConfirm});
@override
State<CreateGameDialogManual> createState() => _CreateGameDialogManualState();
}
class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
late TextEditingController _seasonController;
String _myTeamName = "";
String _opponentName = "";
@override
void initState() {
super.initState();
_seasonController = TextEditingController(text: _calculateSeason());
}
@override
void dispose() {
_seasonController.dispose();
super.dispose();
}
String _calculateSeason() {
final now = DateTime.now();
return now.month >= 7 ? "${now.year}/${(now.year + 1).toString().substring(2)}" : "${now.year - 1}/${now.year.toString().substring(2)}";
}
@override
Widget build(BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
title: const Text('Configurar Partida', style: TextStyle(fontWeight: FontWeight.bold)),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: _seasonController,
decoration: const InputDecoration(
labelText: 'Temporada',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.calendar_today, size: 20),
),
),
const SizedBox(height: 15),
_buildSearch(label: "Minha Equipa", onSelect: (v) => _myTeamName = v),
const Padding(padding: EdgeInsets.symmetric(vertical: 8), child: Text("VS", style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey))),
_buildSearch(label: "Adversário", onSelect: (v) => _opponentName = v),
],
),
),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text('CANCELAR')),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFE74C3C),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
),
onPressed: () {
if (_myTeamName.isNotEmpty && _opponentName.isNotEmpty) {
// 1. Criar um ID único para este jogo
final String newGameId = DateTime.now().toString();
// 2. Notificar a GamePage para criar o card (via onConfirm)
widget.onConfirm(_myTeamName, _opponentName, _seasonController.text);
// 3. Fechar o popup de criação
Navigator.pop(context);
// 4. Ir direto para a tela do marcador de pontos
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PlacarPage(
gameId: newGameId,
myTeam: _myTeamName,
opponentTeam: _opponentName,
),
),
);
}
},
child: const Text('CRIAR', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
),
],
);
}
Widget _buildSearch({required String label, required Function(String) onSelect}) {
return StreamBuilder<List<Map<String, dynamic>>>(
stream: widget.controller.teamsStream,
builder: (context, snapshot) {
List<String> teamList = snapshot.hasData ? snapshot.data!.map((t) => t['name'].toString()).toList() : [];
return Autocomplete<String>(
optionsBuilder: (val) => val.text.isEmpty ? [] : teamList.where((t) => t.toLowerCase().contains(val.text.toLowerCase())),
fieldViewBuilder: (ctx, ctrl, node, submit) => TextField(
controller: ctrl,
focusNode: node,
onChanged: onSelect,
decoration: InputDecoration(
labelText: label,
prefixIcon: const Icon(Icons.search),
border: const OutlineInputBorder()
),
),
);
},
);
}
}

View File

@@ -0,0 +1,140 @@
import 'package:flutter/material.dart';
import '../models/team_model.dart';
import '../models/person_model.dart';
// --- CABEÇALHO ---
class StatsHeader extends StatelessWidget {
final Team team;
const StatsHeader({super.key, required this.team});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.only(top: 50, left: 20, right: 20, bottom: 20),
decoration: const BoxDecoration(
color: Color(0xFF2C3E50),
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(30), bottomRight: Radius.circular(30)),
),
child: Row(
children: [
IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.pop(context),
),
const SizedBox(width: 10),
CircleAvatar(
backgroundColor: Colors.white24,
child: Text(team.imageUrl.isNotEmpty ? "📷" : "🛡️"),
),
const SizedBox(width: 15),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(team.name, style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold)),
Text(team.season, style: const TextStyle(color: Colors.white70, fontSize: 14)),
],
),
],
),
);
}
}
// --- CARD DE RESUMO ---
class StatsSummaryCard extends StatelessWidget {
final int total;
const StatsSummaryCard({super.key, required this.total});
@override
Widget build(BuildContext context) {
return Card(
elevation: 4,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
child: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: LinearGradient(colors: [Colors.blue.shade700, Colors.blue.shade400]),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text("Total de Membros", style: TextStyle(color: Colors.white, fontSize: 16)),
Text("$total", style: const TextStyle(color: Colors.white, fontSize: 28, fontWeight: FontWeight.bold)),
],
),
),
);
}
}
// --- TÍTULO DE SECÇÃO ---
class StatsSectionTitle extends StatelessWidget {
final String title;
const StatsSectionTitle({super.key, required this.title});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Color(0xFF2C3E50))),
const Divider(),
],
);
}
}
// --- CARD DA PESSOA (JOGADOR/TREINADOR) ---
class PersonCard extends StatelessWidget {
final Person person;
final bool isCoach;
final VoidCallback onEdit;
final VoidCallback onDelete;
const PersonCard({
super.key,
required this.person,
required this.isCoach,
required this.onEdit,
required this.onDelete,
});
@override
Widget build(BuildContext context) {
return Card(
margin: const EdgeInsets.only(top: 12),
elevation: 2,
color: isCoach ? const Color(0xFFFFF9C4) : Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
child: ListTile(
leading: isCoach
? const CircleAvatar(backgroundColor: Colors.orange, child: Icon(Icons.person, color: Colors.white))
: Container(
width: 45,
height: 45,
alignment: Alignment.center,
decoration: BoxDecoration(color: Colors.blue.withOpacity(0.1), borderRadius: BorderRadius.circular(10)),
child: Text(person.number, style: const TextStyle(color: Colors.blue, fontWeight: FontWeight.bold, fontSize: 16)),
),
title: Text(person.name, style: const TextStyle(fontWeight: FontWeight.bold)),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: const Icon(Icons.edit_outlined, color: Colors.blue),
onPressed: onEdit,
),
IconButton(
icon: const Icon(Icons.delete_outline, color: Colors.red),
onPressed: onDelete,
),
],
),
),
);
}
}

View File

@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:playmaker/screens/team_stats_page.dart';
import '../models/team_model.dart';
import '../controllers/team_controller.dart';
import '../screens/team_stats_page.dart';
class TeamCard extends StatelessWidget {
final Team team;
final TeamController controller;
@@ -17,40 +18,37 @@ class TeamCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Card(
color: Colors.white,
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: Stack(
clipBehavior: Clip.none, // Permite que a estrela flutue ligeiramente fora do círculo
// --- 1. IMAGEM + FAVORITO ---
leading: Stack(
clipBehavior: Clip.none,
children: [
// 1. IMAGEM DA EQUIPA
CircleAvatar(
radius: 28,
backgroundColor: Colors.grey[200],
backgroundImage: (team.imageUrl.isNotEmpty && team.imageUrl.startsWith('http'))
? NetworkImage(team.imageUrl)
backgroundImage: (team.imageUrl.isNotEmpty && team.imageUrl.startsWith('http'))
? NetworkImage(team.imageUrl)
: null,
child: (team.imageUrl.isEmpty || !team.imageUrl.startsWith('http'))
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
left: -15,
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
color: team.isFavorite ? Colors.amber : Colors.black.withOpacity(0.1),
size: 28,
shadows: [
Shadow(
@@ -65,13 +63,13 @@ class TeamCard extends StatelessWidget {
],
),
// --- NOME DA EQUIPA ---
// --- 2. TÍTULO ---
title: Text(
team.name,
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
// --- SUBTÍTULO (CONTAGEM E TEMPORADA) ---
// --- 3. SUBTÍTULO (Contagem + Época) ---
subtitle: Padding(
padding: const EdgeInsets.only(top: 6.0),
child: Row(
@@ -102,9 +100,9 @@ class TeamCard extends StatelessWidget {
),
),
// --- BOTÕES DE ACÇÃO À DIREITA ---
// --- 4. BOTÕES (Estatísticas e Apagar) ---
trailing: SizedBox(
width: 80,
width: 96, // Aumentei um pouco para caberem bem os dois botões
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
@@ -112,6 +110,7 @@ class TeamCard extends StatelessWidget {
tooltip: 'Ver Estatísticas',
icon: const Icon(Icons.bar_chart_rounded, color: Colors.blue),
onPressed: () {
// CORRIGIDO: Agora chama a classe TeamStatsPage corretamente
Navigator.push(
context,
MaterialPageRoute(
@@ -131,6 +130,8 @@ class TeamCard extends StatelessWidget {
),
);
}
// Função de confirmação de exclusão
void _confirmDelete(BuildContext context) {
showDialog(
context: context,
@@ -139,22 +140,23 @@ class TeamCard extends StatelessWidget {
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);
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)),
),
],
),
);
}
}
// --- DIALOG DE CRIAÇÃO ---
class CreateTeamDialog extends StatefulWidget {
final Function(String name, String season, String imageUrl) onConfirm;
@@ -206,16 +208,16 @@ class _CreateTeamDialogState extends State<CreateTeamDialog> {
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()
);
Navigator.pop(context);
}
},
onPressed: () {
if (_nameController.text.trim().isNotEmpty) {
widget.onConfirm(
_nameController.text.trim(),
_selectedSeason,
_imageController.text.trim(),
);
Navigator.pop(context);
}
},
child: const Text('Criar', style: TextStyle(color: Colors.white)),
),
],