vai te lixar github
This commit is contained in:
@@ -1,158 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:playmaker/screens/team_stats_page.dart';
|
||||
import 'package:playmaker/classe/theme.dart'; // 👇 IMPORT DO TEMA
|
||||
import '../models/team_model.dart';
|
||||
import '../controllers/team_controller.dart';
|
||||
import '../models/person_model.dart';
|
||||
import '../utils/size_extension.dart'; // 👇 O NOSSO SUPERPODER!
|
||||
|
||||
class TeamCard extends StatelessWidget {
|
||||
// --- CABEÇALHO ---
|
||||
class StatsHeader extends StatelessWidget {
|
||||
final Team team;
|
||||
final TeamController controller;
|
||||
final VoidCallback onFavoriteTap;
|
||||
final double sf; // <-- Variável de escala
|
||||
|
||||
const TeamCard({
|
||||
super.key,
|
||||
required this.team,
|
||||
required this.controller,
|
||||
required this.onFavoriteTap,
|
||||
required this.sf,
|
||||
});
|
||||
const StatsHeader({super.key, required this.team});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
color: Colors.white,
|
||||
elevation: 3,
|
||||
margin: EdgeInsets.only(bottom: 12 * sf),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15 * sf)),
|
||||
child: ListTile(
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 16 * sf, vertical: 8 * sf),
|
||||
|
||||
// --- 1. IMAGEM + FAVORITO ---
|
||||
leading: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 28 * sf,
|
||||
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: TextStyle(fontSize: 24 * sf),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
Positioned(
|
||||
left: -15 * sf,
|
||||
top: -10 * sf,
|
||||
child: IconButton(
|
||||
icon: Icon(
|
||||
team.isFavorite ? Icons.star : Icons.star_border,
|
||||
color: team.isFavorite ? Colors.amber : Colors.black.withOpacity(0.1),
|
||||
size: 28 * sf,
|
||||
shadows: [
|
||||
Shadow(
|
||||
color: Colors.black.withOpacity(team.isFavorite ? 0.3 : 0.1),
|
||||
blurRadius: 4 * sf,
|
||||
),
|
||||
],
|
||||
),
|
||||
onPressed: onFavoriteTap,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// --- 2. TÍTULO ---
|
||||
title: Text(
|
||||
team.name,
|
||||
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16 * sf),
|
||||
overflow: TextOverflow.ellipsis, // Previne overflows em nomes longos
|
||||
),
|
||||
|
||||
// --- 3. SUBTÍTULO (Contagem + Época em TEMPO REAL) ---
|
||||
subtitle: Padding(
|
||||
padding: EdgeInsets.only(top: 6.0 * sf),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.groups_outlined, size: 16 * sf, color: Colors.grey),
|
||||
SizedBox(width: 4 * sf),
|
||||
|
||||
// 👇 A CORREÇÃO ESTÁ AQUI: StreamBuilder em vez de FutureBuilder 👇
|
||||
StreamBuilder<int>(
|
||||
stream: controller.getPlayerCountStream(team.id),
|
||||
initialData: 0,
|
||||
builder: (context, snapshot) {
|
||||
final count = snapshot.data ?? 0;
|
||||
return Text(
|
||||
"$count Jogs.", // Abreviado para poupar espaço
|
||||
style: TextStyle(
|
||||
color: count > 0 ? Colors.green[700] : Colors.orange,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 13 * sf,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
SizedBox(width: 8 * sf),
|
||||
Expanded( // Garante que a temporada se adapta se faltar espaço
|
||||
child: Text(
|
||||
"| ${team.season}",
|
||||
style: TextStyle(color: Colors.grey, fontSize: 13 * sf),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// --- 4. BOTÕES (Estatísticas e Apagar) ---
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min, // <-- ISTO RESOLVE O OVERFLOW DAS RISCAS AMARELAS
|
||||
children: [
|
||||
IconButton(
|
||||
tooltip: 'Ver Estatísticas',
|
||||
icon: Icon(Icons.bar_chart_rounded, color: Colors.blue, size: 24 * sf),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TeamStatsPage(team: team),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
tooltip: 'Eliminar Equipa',
|
||||
icon: Icon(Icons.delete_outline, color: const Color(0xFFE74C3C), size: 24 * sf),
|
||||
onPressed: () => _confirmDelete(context),
|
||||
),
|
||||
],
|
||||
return Container(
|
||||
padding: EdgeInsets.only(
|
||||
top: 50 * context.sf,
|
||||
left: 20 * context.sf,
|
||||
right: 20 * context.sf,
|
||||
bottom: 20 * context.sf
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primaryRed, // 👇 Usando a cor do teu tema!
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(30 * context.sf),
|
||||
bottomRight: Radius.circular(30 * context.sf)
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _confirmDelete(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Eliminar Equipa?', style: TextStyle(fontSize: 18 * sf, fontWeight: FontWeight.bold)),
|
||||
content: Text('Tens a certeza que queres eliminar "${team.name}"?', style: TextStyle(fontSize: 14 * sf)),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.arrow_back, color: Colors.white, size: 24 * context.sf),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text('Cancelar', style: TextStyle(fontSize: 14 * sf)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
controller.deleteTeam(team.id);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text('Eliminar', style: TextStyle(color: Colors.red, fontSize: 14 * sf)),
|
||||
SizedBox(width: 10 * context.sf),
|
||||
CircleAvatar(
|
||||
radius: 24 * context.sf,
|
||||
backgroundColor: Colors.white24,
|
||||
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: TextStyle(fontSize: 20 * context.sf),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
SizedBox(width: 15 * context.sf),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
team.name,
|
||||
style: TextStyle(color: Colors.white, fontSize: 20 * context.sf, fontWeight: FontWeight.bold),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
team.season,
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14 * context.sf)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -160,90 +69,164 @@ class TeamCard extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
// --- DIALOG DE CRIAÇÃO ---
|
||||
class CreateTeamDialog extends StatefulWidget {
|
||||
final Function(String name, String season, String imageUrl) onConfirm;
|
||||
final double sf; // Recebe a escala
|
||||
// --- CARD DE RESUMO ---
|
||||
class StatsSummaryCard extends StatelessWidget {
|
||||
final int total;
|
||||
|
||||
const CreateTeamDialog({super.key, required this.onConfirm, required this.sf});
|
||||
|
||||
@override
|
||||
State<CreateTeamDialog> createState() => _CreateTeamDialogState();
|
||||
}
|
||||
|
||||
class _CreateTeamDialogState extends State<CreateTeamDialog> {
|
||||
final TextEditingController _nameController = TextEditingController();
|
||||
final TextEditingController _imageController = TextEditingController();
|
||||
String _selectedSeason = '2024/25';
|
||||
const StatsSummaryCard({super.key, required this.total});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15 * widget.sf)),
|
||||
title: Text('Nova Equipa', style: TextStyle(fontSize: 18 * widget.sf, fontWeight: FontWeight.bold)),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
// 👇 Adaptável ao Modo Escuro
|
||||
final cardColor = Theme.of(context).brightness == Brightness.dark
|
||||
? const Color(0xFF1E1E1E)
|
||||
: Colors.white;
|
||||
|
||||
return Card(
|
||||
elevation: 4,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20 * context.sf)),
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(20 * context.sf),
|
||||
decoration: BoxDecoration(
|
||||
color: cardColor,
|
||||
borderRadius: BorderRadius.circular(20 * context.sf),
|
||||
border: Border.all(color: Colors.grey.withOpacity(0.15)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
TextField(
|
||||
controller: _nameController,
|
||||
style: TextStyle(fontSize: 14 * widget.sf),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Nome da Equipa',
|
||||
labelStyle: TextStyle(fontSize: 14 * widget.sf)
|
||||
),
|
||||
textCapitalization: TextCapitalization.words,
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.groups, color: AppTheme.primaryRed, size: 28 * context.sf), // 👇 Cor do tema
|
||||
SizedBox(width: 10 * context.sf),
|
||||
Text(
|
||||
"Total de Membros",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onSurface, // 👇 Adaptável
|
||||
fontSize: 16 * context.sf,
|
||||
fontWeight: FontWeight.w600
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 15 * widget.sf),
|
||||
DropdownButtonFormField<String>(
|
||||
value: _selectedSeason,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Temporada',
|
||||
labelStyle: TextStyle(fontSize: 14 * widget.sf)
|
||||
),
|
||||
style: TextStyle(fontSize: 14 * widget.sf, color: Colors.black87),
|
||||
items: ['2023/24', '2024/25', '2025/26']
|
||||
.map((s) => DropdownMenuItem(value: s, child: Text(s)))
|
||||
.toList(),
|
||||
onChanged: (val) => setState(() => _selectedSeason = val!),
|
||||
),
|
||||
SizedBox(height: 15 * widget.sf),
|
||||
TextField(
|
||||
controller: _imageController,
|
||||
style: TextStyle(fontSize: 14 * widget.sf),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'URL Imagem ou Emoji',
|
||||
labelStyle: TextStyle(fontSize: 14 * widget.sf),
|
||||
hintText: 'Ex: 🏀 ou https://...',
|
||||
hintStyle: TextStyle(fontSize: 14 * widget.sf)
|
||||
),
|
||||
Text(
|
||||
"$total",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onSurface, // 👇 Adaptável
|
||||
fontSize: 28 * context.sf,
|
||||
fontWeight: FontWeight.bold
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text('Cancelar', style: TextStyle(fontSize: 14 * widget.sf))
|
||||
),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFFE74C3C),
|
||||
padding: EdgeInsets.symmetric(horizontal: 16 * widget.sf, vertical: 10 * widget.sf)
|
||||
),
|
||||
onPressed: () {
|
||||
if (_nameController.text.trim().isNotEmpty) {
|
||||
widget.onConfirm(
|
||||
_nameController.text.trim(),
|
||||
_selectedSeason,
|
||||
_imageController.text.trim(),
|
||||
);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
child: Text('Criar', style: TextStyle(color: Colors.white, fontSize: 14 * widget.sf)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// --- 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: TextStyle(
|
||||
fontSize: 18 * context.sf,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Theme.of(context).colorScheme.onSurface // 👇 Adaptável
|
||||
)
|
||||
),
|
||||
Divider(color: Colors.grey.withOpacity(0.3)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// --- 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) {
|
||||
// 👇 Cores adaptáveis para o Card
|
||||
final defaultBg = Theme.of(context).brightness == Brightness.dark
|
||||
? const Color(0xFF1E1E1E)
|
||||
: Colors.white;
|
||||
|
||||
final coachBg = Theme.of(context).brightness == Brightness.dark
|
||||
? AppTheme.warningAmber.withOpacity(0.1) // Amarelo escuro se for modo noturno
|
||||
: const Color(0xFFFFF9C4); // Amarelo claro original
|
||||
|
||||
return Card(
|
||||
margin: EdgeInsets.only(top: 12 * context.sf),
|
||||
elevation: 2,
|
||||
color: isCoach ? coachBg : defaultBg,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15 * context.sf)),
|
||||
child: ListTile(
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 16 * context.sf, vertical: 4 * context.sf),
|
||||
leading: isCoach
|
||||
? CircleAvatar(
|
||||
radius: 22 * context.sf,
|
||||
backgroundColor: AppTheme.warningAmber, // 👇 Cor do tema
|
||||
child: Icon(Icons.person, color: Colors.white, size: 24 * context.sf)
|
||||
)
|
||||
: Container(
|
||||
width: 45 * context.sf,
|
||||
height: 45 * context.sf,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primaryRed.withOpacity(0.1), // 👇 Cor do tema
|
||||
borderRadius: BorderRadius.circular(10 * context.sf)
|
||||
),
|
||||
child: Text(
|
||||
person.number ?? "J",
|
||||
style: TextStyle(
|
||||
color: AppTheme.primaryRed, // 👇 Cor do tema
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16 * context.sf
|
||||
)
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
person.name,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16 * context.sf,
|
||||
color: Theme.of(context).colorScheme.onSurface, // 👇 Adaptável
|
||||
)
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit_outlined, color: Colors.blue, size: 22 * context.sf),
|
||||
onPressed: onEdit,
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete_outline, color: AppTheme.primaryRed, size: 22 * context.sf), // 👇 Cor do tema
|
||||
onPressed: onDelete,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user