fazer vitoria e derrota

This commit is contained in:
2026-03-10 17:15:10 +00:00
parent d720e09866
commit 49bb371ef4
12 changed files with 940 additions and 742 deletions

View File

@@ -3,6 +3,7 @@ import 'package:playmaker/screens/team_stats_page.dart';
import '../controllers/team_controller.dart';
import '../models/team_model.dart';
import '../widgets/team_widgets.dart';
import 'dart:math' as math; // <-- IMPORTANTE: Adicionar para o cálculo
class TeamsPage extends StatefulWidget {
const TeamsPage({super.key});
@@ -26,24 +27,24 @@ class _TeamsPageState extends State<TeamsPage> {
}
// --- POPUP DE FILTROS ---
void _showFilterDialog(BuildContext context) {
void _showFilterDialog(BuildContext context, double sf) {
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (context, setModalState) {
return AlertDialog(
backgroundColor: const Color(0xFF2C3E50), // 2. CORRIGIDO: Fundo escuro
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
backgroundColor: const Color(0xFF2C3E50),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20 * sf)),
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
Text(
"Filtros de pesquisa",
style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
style: TextStyle(color: Colors.white, fontSize: 18 * sf, fontWeight: FontWeight.bold),
),
IconButton(
icon: const Icon(Icons.close, color: Colors.white, size: 20),
icon: Icon(Icons.close, color: Colors.white, size: 20 * sf),
onPressed: () => Navigator.pop(context),
)
],
@@ -52,7 +53,7 @@ class _TeamsPageState extends State<TeamsPage> {
mainAxisSize: MainAxisSize.min,
children: [
const Divider(color: Colors.white24),
const SizedBox(height: 16),
SizedBox(height: 16 * sf),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -62,19 +63,21 @@ class _TeamsPageState extends State<TeamsPage> {
title: "TEMPORADA",
options: ['Todas', '2023/24', '2024/25', '2025/26'],
currentValue: _selectedSeason,
sf: sf,
onSelect: (val) {
setState(() => _selectedSeason = val);
setModalState(() {});
},
),
),
const SizedBox(width: 20),
SizedBox(width: 20 * sf),
// Coluna Ordenar
Expanded(
child: _buildPopupColumn(
title: "ORDENAR POR",
options: ['Recentes', 'Nome', 'Tamanho'],
currentValue: _currentSort,
sf: sf,
onSelect: (val) {
setState(() => _currentSort = val);
setModalState(() {});
@@ -88,7 +91,7 @@ class _TeamsPageState extends State<TeamsPage> {
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text("CONCLUÍDO", style: TextStyle(color: Color(0xFFE74C3C), fontWeight: FontWeight.bold)),
child: Text("CONCLUÍDO", style: TextStyle(color: const Color(0xFFE74C3C), fontWeight: FontWeight.bold, fontSize: 14 * sf)),
),
],
);
@@ -102,25 +105,26 @@ class _TeamsPageState extends State<TeamsPage> {
required String title,
required List<String> options,
required String currentValue,
required double sf,
required Function(String) onSelect,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: const TextStyle(color: Colors.grey, fontSize: 11, fontWeight: FontWeight.bold)),
const SizedBox(height: 12),
Text(title, style: TextStyle(color: Colors.grey, fontSize: 11 * sf, fontWeight: FontWeight.bold)),
SizedBox(height: 12 * sf),
...options.map((opt) {
final isSelected = currentValue == opt;
return InkWell(
onTap: () => onSelect(opt),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
padding: EdgeInsets.symmetric(vertical: 8.0 * sf),
child: Text(
opt,
style: TextStyle(
// 3. CORRIGIDO: Cor do texto (Branco se não selecionado, Vermelho se selecionado)
color: isSelected ? const Color(0xFFE74C3C) : Colors.white70,
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
fontSize: 14 * sf,
),
),
),
@@ -132,51 +136,57 @@ class _TeamsPageState extends State<TeamsPage> {
@override
Widget build(BuildContext context) {
// 👇 CÁLCULO DA ESCALA (sf) PARA SE ADAPTAR A QUALQUER ECRÃ 👇
final double wScreen = MediaQuery.of(context).size.width;
final double hScreen = MediaQuery.of(context).size.height;
final double sf = math.min(wScreen, hScreen) / 400;
return Scaffold(
backgroundColor: const Color(0xFFF5F7FA),
appBar: AppBar(
title: const Text("Minhas Equipas", style: TextStyle(fontWeight: FontWeight.bold)),
title: Text("Minhas Equipas", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20 * sf)),
backgroundColor: const Color(0xFFF5F7FA),
elevation: 0,
actions: [
IconButton(
icon: const Icon(Icons.filter_list, color: Color(0xFFE74C3C)),
onPressed: () => _showFilterDialog(context),
icon: Icon(Icons.filter_list, color: const Color(0xFFE74C3C), size: 24 * sf),
onPressed: () => _showFilterDialog(context, sf),
),
],
),
body: Column(
children: [
_buildSearchBar(),
Expanded(child: _buildTeamsList()),
_buildSearchBar(sf),
Expanded(child: _buildTeamsList(sf)),
],
),
floatingActionButton: FloatingActionButton(
backgroundColor: const Color(0xFFE74C3C),
child: const Icon(Icons.add, color: Colors.white),
onPressed: () => _showCreateDialog(context),
child: Icon(Icons.add, color: Colors.white, size: 24 * sf),
onPressed: () => _showCreateDialog(context, sf),
),
);
}
Widget _buildSearchBar() {
Widget _buildSearchBar(double sf) {
return Padding(
padding: const EdgeInsets.all(16.0),
padding: EdgeInsets.all(16.0 * sf),
child: TextField(
controller: _searchController,
onChanged: (v) => setState(() => _searchQuery = v.toLowerCase()),
style: TextStyle(fontSize: 16 * sf),
decoration: InputDecoration(
hintText: 'Pesquisar equipa...',
prefixIcon: const Icon(Icons.search, color: Color(0xFFE74C3C)),
hintStyle: TextStyle(fontSize: 16 * sf),
prefixIcon: Icon(Icons.search, color: const Color(0xFFE74C3C), size: 22 * sf),
filled: true,
fillColor: Colors.white,
border: OutlineInputBorder(borderRadius: BorderRadius.circular(15), borderSide: BorderSide.none),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(15 * sf), borderSide: BorderSide.none),
),
),
);
}
Widget _buildTeamsList() {
Widget _buildTeamsList(double sf) {
return StreamBuilder<List<Map<String, dynamic>>>(
stream: controller.teamsStream,
builder: (context, snapshot) {
@@ -185,7 +195,7 @@ class _TeamsPageState extends State<TeamsPage> {
}
if (!snapshot.hasData || snapshot.data!.isEmpty) {
return const Center(child: Text("Nenhuma equipa encontrada."));
return Center(child: Text("Nenhuma equipa encontrada.", style: TextStyle(fontSize: 16 * sf)));
}
var data = List<Map<String, dynamic>>.from(snapshot.data!);
@@ -198,31 +208,25 @@ class _TeamsPageState extends State<TeamsPage> {
data = data.where((t) => t['name'].toString().toLowerCase().contains(_searchQuery)).toList();
}
// --- 2. ORDENAÇÃO (FAVORITOS PRIMEIRO) ---
// --- 2. ORDENAÇÃO ---
data.sort((a, b) {
// Apanhar o estado de favorito (tratando null como false)
bool favA = a['is_favorite'] ?? false;
bool favB = b['is_favorite'] ?? false;
// REGRA 1: Favoritos aparecem sempre primeiro
if (favA && !favB) return -1; // A sobe
if (!favA && favB) return 1; // B sobe
// REGRA 2: Se o estado de favorito for igual, aplica o filtro do utilizador
if (favA && !favB) return -1;
if (!favA && favB) return 1;
if (_currentSort == 'Nome') {
return a['name'].toString().compareTo(b['name'].toString());
} else { // Recentes
} else {
return (b['created_at'] ?? '').toString().compareTo((a['created_at'] ?? '').toString());
}
});
return ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 16),
padding: EdgeInsets.symmetric(horizontal: 16 * sf),
itemCount: data.length,
itemBuilder: (context, index) {
final team = Team.fromMap(data[index]);
// Navegação para estatísticas
return GestureDetector(
onTap: () {
Navigator.push(
@@ -233,6 +237,7 @@ class _TeamsPageState extends State<TeamsPage> {
child: TeamCard(
team: team,
controller: controller,
sf: sf, // Passar a escala para o Card
onFavoriteTap: () => controller.toggleFavorite(team.id, team.isFavorite),
),
);
@@ -242,14 +247,13 @@ class _TeamsPageState extends State<TeamsPage> {
);
}
void _showCreateDialog(BuildContext context) {
void _showCreateDialog(BuildContext context, double sf) {
showDialog(
context: context,
builder: (context) => CreateTeamDialog(
sf: sf,
onConfirm: (name, season, imageUrl) => controller.createTeam(name, season, imageUrl),
),
);
}
}