fazer vitoria e derrota
This commit is contained in:
@@ -41,7 +41,7 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// --- BOTÕES FLUTUANTES DE FALTA (MUITO MAIS PEQUENOS AQUI 👇) ---
|
||||
// --- BOTÕES FLUTUANTES DE FALTA ---
|
||||
Widget _buildFloatingFoulBtn(String label, Color color, String action, IconData icon, double left, double right, double top, double sf) {
|
||||
return Positioned(
|
||||
top: top,
|
||||
@@ -52,20 +52,20 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
feedback: Material(
|
||||
color: Colors.transparent,
|
||||
child: CircleAvatar(
|
||||
radius: 25 * sf, // Era 35
|
||||
radius: 30 * sf,
|
||||
backgroundColor: color.withOpacity(0.8),
|
||||
child: Icon(icon, color: Colors.white, size: 25 * sf) // Era 35
|
||||
child: Icon(icon, color: Colors.white, size: 30 * sf)
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 22 * sf, // Era 30
|
||||
radius: 27 * sf,
|
||||
backgroundColor: color,
|
||||
child: Icon(icon, color: Colors.white, size: 26 * sf), // Era 35
|
||||
child: Icon(icon, color: Colors.white, size: 28 * sf),
|
||||
),
|
||||
SizedBox(height: 4 * sf),
|
||||
Text(label, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 11 * sf)), // Era 14
|
||||
SizedBox(height: 5 * sf),
|
||||
Text(label, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 12 * sf)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -80,12 +80,12 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
child: FloatingActionButton(
|
||||
heroTag: heroTag,
|
||||
backgroundColor: color,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12 * (size / 50))),
|
||||
elevation: 4,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14 * (size / 50))),
|
||||
elevation: 5,
|
||||
onPressed: isLoading ? null : onTap,
|
||||
child: isLoading
|
||||
? SizedBox(width: size*0.4, height: size*0.4, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2))
|
||||
: Icon(icon, color: Colors.white, size: size * 0.5),
|
||||
? SizedBox(width: size*0.45, height: size*0.45, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2.5))
|
||||
: Icon(icon, color: Colors.white, size: size * 0.55),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -94,9 +94,11 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
Widget build(BuildContext context) {
|
||||
final double wScreen = MediaQuery.of(context).size.width;
|
||||
final double hScreen = MediaQuery.of(context).size.height;
|
||||
final double sf = math.min(wScreen / 1280, hScreen / 800);
|
||||
|
||||
// 👇 DIVISOR AUMENTADO PARA O 'sf' FICAR MAIS PEQUENO 👇
|
||||
final double sf = math.min(wScreen / 1150, hScreen / 720);
|
||||
|
||||
final double cornerBtnSize = 50 * sf;
|
||||
final double cornerBtnSize = 48 * sf; // Tamanho ideal (Nem 38 nem 55)
|
||||
|
||||
if (_controller.isLoading) {
|
||||
return Scaffold(
|
||||
@@ -105,8 +107,8 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text("PREPARANDO O PAVILHÃO", style: TextStyle(color: Colors.white24, fontSize: 40 * sf, fontWeight: FontWeight.bold, letterSpacing: 2)),
|
||||
SizedBox(height: 30 * sf),
|
||||
Text("PREPARANDO O PAVILHÃO", style: TextStyle(color: Colors.white24, fontSize: 45 * sf, fontWeight: FontWeight.bold, letterSpacing: 2)),
|
||||
SizedBox(height: 35 * sf),
|
||||
StreamBuilder(
|
||||
stream: Stream.periodic(const Duration(seconds: 3)),
|
||||
builder: (context, snapshot) {
|
||||
@@ -118,7 +120,7 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
"Os jogadores estão a terminar o aquecimento..."
|
||||
];
|
||||
String frase = frases[DateTime.now().second % frases.length];
|
||||
return Text(frase, style: TextStyle(color: Colors.orange.withOpacity(0.7), fontSize: 24 * sf, fontStyle: FontStyle.italic));
|
||||
return Text(frase, style: TextStyle(color: Colors.orange.withOpacity(0.7), fontSize: 26 * sf, fontStyle: FontStyle.italic));
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -130,12 +132,14 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFF266174),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: Stack(
|
||||
children: [
|
||||
// --- O CAMPO ---
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: 60 * sf, right: 60 * sf, bottom: 50 * sf),
|
||||
decoration: BoxDecoration(border: Border.all(color: Colors.white, width: 2.0)),
|
||||
margin: EdgeInsets.only(left: 65 * sf, right: 65 * sf, bottom: 55 * sf),
|
||||
decoration: BoxDecoration(border: Border.all(color: Colors.white, width: 2.5)),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final w = constraints.maxWidth;
|
||||
@@ -151,12 +155,14 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
},
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(image: AssetImage('assets/campo.png'), fit: BoxFit.cover, alignment: Alignment(0.0, 0.2)),
|
||||
),
|
||||
image: DecorationImage(
|
||||
image: AssetImage('assets/campo.png'),
|
||||
fit: BoxFit.fill, // <-- A MÁGICA ESTÁ AQUI
|
||||
), ),
|
||||
child: Stack(
|
||||
children: _controller.matchShots.map((shot) => Positioned(
|
||||
left: shot.position.dx - (8 * sf), top: shot.position.dy - (8 * sf),
|
||||
child: CircleAvatar(radius: 8 * sf, backgroundColor: shot.isMake ? Colors.green : Colors.red, child: Icon(shot.isMake ? Icons.check : Icons.close, size: 10 * sf, color: Colors.white)),
|
||||
left: shot.position.dx - (9 * sf), top: shot.position.dy - (9 * sf),
|
||||
child: CircleAvatar(radius: 9 * sf, backgroundColor: shot.isMake ? Colors.green : Colors.red, child: Icon(shot.isMake ? Icons.check : Icons.close, size: 11 * sf, color: Colors.white)),
|
||||
)).toList(),
|
||||
),
|
||||
),
|
||||
@@ -179,27 +185,32 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
|
||||
// --- BOTÕES DE FALTAS ---
|
||||
if (!_controller.isSelectingShotLocation) ...[
|
||||
_buildFloatingFoulBtn("FALTA +", Colors.orange, "add_foul", Icons.sports, w * 0.38, 0.0, h * 0.30, sf),
|
||||
_buildFloatingFoulBtn("FALTA -", Colors.redAccent, "sub_foul", Icons.block, 0.0, w * 0.38, h * 0.30, sf),
|
||||
_buildFloatingFoulBtn("FALTA +", Colors.orange, "add_foul", Icons.sports, w * 0.39, 0.0, h * 0.31, sf),
|
||||
_buildFloatingFoulBtn("FALTA -", Colors.redAccent, "sub_foul", Icons.block, 0.0, w * 0.39, h * 0.31, sf),
|
||||
],
|
||||
|
||||
// --- BOTÃO PLAY/PAUSE ---
|
||||
if (!_controller.isSelectingShotLocation)
|
||||
Positioned(
|
||||
top: (h * 0.30) + (100 * sf), left: 0, right: 0,
|
||||
child: Center(
|
||||
child: GestureDetector(
|
||||
onTap: () => _controller.toggleTimer(context),
|
||||
child: CircleAvatar(radius: 60 * sf, backgroundColor: Colors.grey.withOpacity(0.5), child: Icon(_controller.isRunning ? Icons.pause : Icons.play_arrow, color: Colors.white, size: 50 * sf)),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!_controller.isSelectingShotLocation)
|
||||
Positioned(
|
||||
|
||||
top: (h * 0.32) + (40 * sf),
|
||||
left: 0, right: 0,
|
||||
child: Center(
|
||||
child: GestureDetector(
|
||||
onTap: () => _controller.toggleTimer(context),
|
||||
child: CircleAvatar(
|
||||
radius: 68 * sf,
|
||||
backgroundColor: Colors.grey.withOpacity(0.5),
|
||||
child: Icon(_controller.isRunning ? Icons.pause : Icons.play_arrow, color: Colors.white, size: 58 * sf)
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// --- PLACAR NO TOPO ---
|
||||
Positioned(top: 0, left: 0, right: 0, child: Center(child: TopScoreboard(controller: _controller, sf: sf))),
|
||||
|
||||
// --- BOTÕES DE AÇÃO ---
|
||||
if (!_controller.isSelectingShotLocation) Positioned(bottom: 10 * sf, left: 0, right: 0, child: ActionButtonsPanel(controller: _controller, sf: sf)),
|
||||
if (!_controller.isSelectingShotLocation) Positioned(bottom: -10 * sf, left: 0, right: 0, child: ActionButtonsPanel(controller: _controller, sf: sf)),
|
||||
|
||||
// --- OVERLAY LANÇAMENTO ---
|
||||
if (_controller.isSelectingShotLocation)
|
||||
@@ -207,9 +218,9 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
top: h * 0.4, left: 0, right: 0,
|
||||
child: Center(
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 30 * sf, vertical: 15 * sf),
|
||||
decoration: BoxDecoration(color: Colors.black87, borderRadius: BorderRadius.circular(10 * sf), border: Border.all(color: Colors.white)),
|
||||
child: Text("TOQUE NO CAMPO PARA MARCAR O LOCAL DO LANÇAMENTO", style: TextStyle(color: Colors.white, fontSize: 24 * sf, fontWeight: FontWeight.bold)),
|
||||
padding: EdgeInsets.symmetric(horizontal: 35 * sf, vertical: 18 * sf),
|
||||
decoration: BoxDecoration(color: Colors.black87, borderRadius: BorderRadius.circular(11 * sf), border: Border.all(color: Colors.white, width: 1.5 * sf)),
|
||||
child: Text("TOQUE NO CAMPO PARA MARCAR O LOCAL DO LANÇAMENTO", style: TextStyle(color: Colors.white, fontSize: 27 * sf, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -220,46 +231,73 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
),
|
||||
|
||||
// --- BOTÕES LATERAIS ---
|
||||
if (!_controller.isSelectingShotLocation) ...[
|
||||
// Topo Esquerdo: Guardar e Sair
|
||||
Positioned(
|
||||
top: 20 * sf, left: 10 * sf,
|
||||
child: Column(
|
||||
children: [
|
||||
_buildCornerBtn(heroTag: 'btn_save', icon: Icons.save, color: const Color(0xFF16202C), size: cornerBtnSize, isLoading: _controller.isSaving, onTap: () => _controller.saveGameStats(context)),
|
||||
SizedBox(height: 15 * sf),
|
||||
_buildCornerBtn(heroTag: 'btn_exit', icon: Icons.exit_to_app, color: const Color(0xFFD92C2C), size: cornerBtnSize, onTap: () => Navigator.pop(context)),
|
||||
],
|
||||
)
|
||||
),
|
||||
// Topo Esquerdo: Guardar e Sair (Botão Único)
|
||||
Positioned(
|
||||
top: 50 * sf, left: 12 * sf,
|
||||
child: _buildCornerBtn(
|
||||
heroTag: 'btn_save_exit',
|
||||
icon: Icons.save_alt, // Mudei o ícone para dar a ideia de "Guardar e Sair"
|
||||
color: const Color(0xFFD92C2C), // Mantive vermelho para saberes que é para fechar
|
||||
size: cornerBtnSize,
|
||||
isLoading: _controller.isSaving,
|
||||
onTap: () async {
|
||||
// 1. Primeiro obriga a guardar os dados na BD
|
||||
await _controller.saveGameStats(context);
|
||||
|
||||
// 2. Só depois de acabar de guardar é que volta para trás (sai da página)
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
),
|
||||
),
|
||||
|
||||
// Base Esquerda: Banco Casa
|
||||
// Base Esquerda: Banco Casa + TIMEOUT DA CASA
|
||||
Positioned(
|
||||
bottom: 50 * sf, left: 10 * sf,
|
||||
bottom: 55 * sf, left: 12 * sf,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (_controller.showMyBench) BenchPlayersList(controller: _controller, isOpponent: false, sf: sf),
|
||||
SizedBox(height: 10 * sf),
|
||||
_buildCornerBtn(heroTag: 'btn_sub_home', icon: Icons.swap_horiz, color: const Color(0xFF1E5BB2), size: cornerBtnSize, onTap: () { _controller.showMyBench = !_controller.showMyBench; _controller.onUpdate(); })
|
||||
SizedBox(height: 12 * sf),
|
||||
_buildCornerBtn(heroTag: 'btn_sub_home', icon: Icons.swap_horiz, color: const Color(0xFF1E5BB2), size: cornerBtnSize, onTap: () { _controller.showMyBench = !_controller.showMyBench; _controller.onUpdate(); }),
|
||||
SizedBox(height: 12 * sf),
|
||||
_buildCornerBtn(
|
||||
heroTag: 'btn_to_home',
|
||||
icon: Icons.timer,
|
||||
color: _controller.myTimeoutsUsed >= 3 ? Colors.grey : const Color(0xFF1E5BB2),
|
||||
size: cornerBtnSize,
|
||||
onTap: _controller.myTimeoutsUsed >= 3
|
||||
? () => ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('🛑 A equipa da casa já usou os 3 Timeouts deste período!'), backgroundColor: Colors.red))
|
||||
: () => _controller.useTimeout(false)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Base Direita: Banco Visitante
|
||||
// Base Direita: Banco Visitante + TIMEOUT DO VISITANTE
|
||||
Positioned(
|
||||
bottom: 50 * sf, right: 10 * sf,
|
||||
bottom: 55 * sf, right: 12 * sf,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (_controller.showOppBench) BenchPlayersList(controller: _controller, isOpponent: true, sf: sf),
|
||||
SizedBox(height: 10 * sf),
|
||||
_buildCornerBtn(heroTag: 'btn_sub_away', icon: Icons.swap_horiz, color: const Color(0xFFD92C2C), size: cornerBtnSize, onTap: () { _controller.showOppBench = !_controller.showOppBench; _controller.onUpdate(); })
|
||||
SizedBox(height: 12 * sf),
|
||||
_buildCornerBtn(heroTag: 'btn_sub_away', icon: Icons.swap_horiz, color: const Color(0xFFD92C2C), size: cornerBtnSize, onTap: () { _controller.showOppBench = !_controller.showOppBench; _controller.onUpdate(); }),
|
||||
SizedBox(height: 12 * sf),
|
||||
_buildCornerBtn(
|
||||
heroTag: 'btn_to_away',
|
||||
icon: Icons.timer,
|
||||
color: _controller.opponentTimeoutsUsed >= 3 ? Colors.grey : const Color(0xFFD92C2C),
|
||||
size: cornerBtnSize,
|
||||
onTap: _controller.opponentTimeoutsUsed >= 3
|
||||
? () => ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('🛑 A equipa visitante já usou os 3 Timeouts deste período!'), backgroundColor: Colors.red))
|
||||
: () => _controller.useTimeout(true)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -3,6 +3,7 @@ import '../controllers/game_controller.dart';
|
||||
import '../controllers/team_controller.dart';
|
||||
import '../models/game_model.dart';
|
||||
import '../widgets/game_widgets.dart';
|
||||
import 'dart:math' as math; // <-- IMPORTANTE: Para o cálculo da escala
|
||||
|
||||
class GamePage extends StatefulWidget {
|
||||
const GamePage({super.key});
|
||||
@@ -17,10 +18,15 @@ class _GamePageState extends State<GamePage> {
|
||||
|
||||
@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("Jogos", style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
title: Text("Jogos", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20 * sf)),
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
@@ -39,15 +45,15 @@ class _GamePageState extends State<GamePage> {
|
||||
}
|
||||
|
||||
if (gameSnapshot.hasError) {
|
||||
return Center(child: Text("Erro: ${gameSnapshot.error}"));
|
||||
return Center(child: Text("Erro: ${gameSnapshot.error}", style: TextStyle(fontSize: 14 * sf)));
|
||||
}
|
||||
|
||||
if (!gameSnapshot.hasData || gameSnapshot.data!.isEmpty) {
|
||||
return const Center(child: Text("Nenhum jogo registado."));
|
||||
return Center(child: Text("Nenhum jogo registado.", style: TextStyle(fontSize: 16 * sf)));
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
padding: EdgeInsets.all(16 * sf),
|
||||
itemCount: gameSnapshot.data!.length,
|
||||
itemBuilder: (context, index) {
|
||||
final game = gameSnapshot.data![index];
|
||||
@@ -65,7 +71,6 @@ class _GamePageState extends State<GamePage> {
|
||||
}
|
||||
}
|
||||
|
||||
// Agora já passamos as imagens para o cartão!
|
||||
return GameResultCard(
|
||||
gameId: game.id,
|
||||
myTeam: game.myTeam,
|
||||
@@ -74,8 +79,9 @@ class _GamePageState extends State<GamePage> {
|
||||
opponentScore: game.opponentScore,
|
||||
status: game.status,
|
||||
season: game.season,
|
||||
myTeamLogo: myLogo, // <-- IMAGEM DA TUA EQUIPA
|
||||
opponentTeamLogo: oppLogo, // <-- IMAGEM DA EQUIPA ADVERSÁRIA
|
||||
myTeamLogo: myLogo,
|
||||
opponentTeamLogo: oppLogo,
|
||||
sf: sf, // <-- Passamos a escala para o Cartão
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -85,18 +91,19 @@ class _GamePageState extends State<GamePage> {
|
||||
),
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showCreateDialog(BuildContext context) {
|
||||
void _showCreateDialog(BuildContext context, double sf) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => CreateGameDialogManual(
|
||||
teamController: teamController,
|
||||
gameController: gameController,
|
||||
sf: sf, // <-- Passamos a escala para o Pop-up
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ import 'package:playmaker/classe/home.config.dart';
|
||||
import 'package:playmaker/grafico%20de%20pizza/grafico.dart';
|
||||
import 'package:playmaker/pages/gamePage.dart';
|
||||
import 'package:playmaker/pages/teamPage.dart';
|
||||
import 'package:playmaker/controllers/team_controller.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import 'dart:math' as math;
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
const HomeScreen({super.key});
|
||||
@@ -13,53 +16,50 @@ class HomeScreen extends StatefulWidget {
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
int _selectedIndex = 0;
|
||||
final TeamController _teamController = TeamController();
|
||||
String? _selectedTeamId;
|
||||
String _selectedTeamName = "Selecionar Equipa";
|
||||
|
||||
|
||||
late final List<Widget> _pages;
|
||||
// Instância do Supabase para buscar as estatísticas
|
||||
final _supabase = Supabase.instance.client;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_pages = [
|
||||
_buildHomeContent(),
|
||||
Widget build(BuildContext context) {
|
||||
final double wScreen = MediaQuery.of(context).size.width;
|
||||
final double hScreen = MediaQuery.of(context).size.height;
|
||||
final double sf = math.min(wScreen, hScreen) / 400;
|
||||
|
||||
final List<Widget> pages = [
|
||||
_buildHomeContent(sf, wScreen),
|
||||
const GamePage(),
|
||||
const TeamsPage(),
|
||||
const Center(child: Text('Tela de Status')),
|
||||
];
|
||||
}
|
||||
|
||||
void _onItemSelected(int index) {
|
||||
setState(() {
|
||||
_selectedIndex = index;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
title: const Text('PlayMaker'),
|
||||
title: Text('PlayMaker', style: TextStyle(fontSize: 20 * sf)),
|
||||
backgroundColor: HomeConfig.primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.person),
|
||||
icon: Icon(Icons.person, size: 24 * sf),
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
|
||||
body: IndexedStack(
|
||||
index: _selectedIndex,
|
||||
children: _pages,
|
||||
children: pages,
|
||||
),
|
||||
|
||||
bottomNavigationBar: NavigationBar(
|
||||
selectedIndex: _selectedIndex,
|
||||
onDestinationSelected: _onItemSelected,
|
||||
onDestinationSelected: (index) => setState(() => _selectedIndex = index),
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
surfaceTintColor: Theme.of(context).colorScheme.surfaceTint,
|
||||
elevation: 1,
|
||||
height: 70,
|
||||
height: 70 * math.min(sf, 1.2),
|
||||
destinations: const [
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.home_outlined),
|
||||
@@ -85,136 +85,230 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
Widget _buildHomeContent() {
|
||||
return SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_buildStatCard(
|
||||
title: 'Mais Pontos',
|
||||
playerName: 'Michael Jordan',
|
||||
statValue: '34.5',
|
||||
statLabel: 'PPG',
|
||||
color: Colors.blue[800]!,
|
||||
icon: Icons.sports_basketball,
|
||||
isHighlighted: true,
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
_buildStatCard(
|
||||
title: 'Mais Assistências',
|
||||
playerName: 'Magic Johnson',
|
||||
statValue: '12.8',
|
||||
statLabel: 'APG',
|
||||
color: Colors.green[800]!,
|
||||
icon: Icons.sports_basketball,
|
||||
isHighlighted: false,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_buildStatCard(
|
||||
title: 'Mais Rebotes',
|
||||
playerName: 'Dennis Rodman',
|
||||
statValue: '15.3',
|
||||
statLabel: 'RPG',
|
||||
color: Colors.purple[800]!,
|
||||
icon: Icons.sports_basketball,
|
||||
isHighlighted: false,
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
PieChartCard(
|
||||
title: 'DESEMPENHO',
|
||||
subtitle: 'Vitórias vs Derrotas',
|
||||
backgroundColor: Colors.red[800]!,
|
||||
onTap: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
Text(
|
||||
'Histórico de Jogos',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// --- POPUP DE SELEÇÃO DE EQUIPA ---
|
||||
void _showTeamSelector(BuildContext context, double sf) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20 * sf)),
|
||||
),
|
||||
builder: (context) {
|
||||
return StreamBuilder<List<Map<String, dynamic>>>(
|
||||
stream: _teamController.teamsStream,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const SizedBox(height: 200, child: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
||||
return SizedBox(height: 200 * sf, child: Center(child: Text("Nenhuma equipa criada.")));
|
||||
}
|
||||
|
||||
final teams = snapshot.data!;
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: teams.length,
|
||||
itemBuilder: (context, index) {
|
||||
final team = teams[index];
|
||||
return ListTile(
|
||||
title: Text(team['name']),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedTeamId = team['id'];
|
||||
_selectedTeamName = team['name'];
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatCard({
|
||||
required String title,
|
||||
required String playerName,
|
||||
required String statValue,
|
||||
required String statLabel,
|
||||
required Color color,
|
||||
required IconData icon,
|
||||
bool isHighlighted = false,
|
||||
}) {
|
||||
return SizedBox(
|
||||
width: HomeConfig.cardwidthPadding,
|
||||
height: HomeConfig.cardheightPadding,
|
||||
child: Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
side: isHighlighted
|
||||
? const BorderSide(color: Colors.amber, width: 2)
|
||||
: BorderSide.none,
|
||||
),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [color.withOpacity(0.9), color.withOpacity(0.7)],
|
||||
),
|
||||
),
|
||||
Widget _buildHomeContent(double sf, double wScreen) {
|
||||
final double cardWidth = (wScreen - (40 * sf) - (20 * sf)) / 2;
|
||||
final double cardHeight = cardWidth * 1.4; // Ajustado para não cortar conteúdo
|
||||
|
||||
return StreamBuilder<List<Map<String, dynamic>>>(
|
||||
// Buscar estatísticas de todos os jogadores da equipa selecionada
|
||||
stream: _selectedTeamId != null
|
||||
? _supabase.from('player_stats_with_names').stream(primaryKey: ['id']).eq('team_id', _selectedTeamId!)
|
||||
: const Stream.empty(),
|
||||
builder: (context, snapshot) {
|
||||
// Lógica de cálculo de líderes
|
||||
Map<String, dynamic> leaders = _calculateLeaders(snapshot.data ?? []);
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
padding: EdgeInsets.all(20.0 * sf),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title.toUpperCase(), style: const TextStyle(fontSize: 12, fontWeight: FontWeight.bold, color: Colors.white70)),
|
||||
Text(playerName, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white)),
|
||||
],
|
||||
),
|
||||
// Seletor de Equipa
|
||||
InkWell(
|
||||
onTap: () => _showTeamSelector(context, sf),
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(12 * sf),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(15 * sf),
|
||||
border: Border.all(color: Colors.grey.shade300),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.shield, color: HomeConfig.primaryColor, size: 24 * sf),
|
||||
SizedBox(width: 10 * sf),
|
||||
Text(_selectedTeamName, style: TextStyle(fontSize: 16 * sf, fontWeight: FontWeight.bold)),
|
||||
],
|
||||
),
|
||||
const Icon(Icons.arrow_drop_down),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 25 * sf),
|
||||
|
||||
// Primeira Linha: Pontos e Assistências
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_buildStatCard(
|
||||
title: 'Mais Pontos',
|
||||
playerName: leaders['pts_name'],
|
||||
statValue: leaders['pts_val'].toString(),
|
||||
statLabel: 'TOTAL',
|
||||
color: const Color(0xFF1565C0),
|
||||
icon: Icons.bolt,
|
||||
isHighlighted: true,
|
||||
sf: sf, cardWidth: cardWidth, cardHeight: cardHeight,
|
||||
),
|
||||
SizedBox(width: 20 * sf),
|
||||
_buildStatCard(
|
||||
title: 'Assistências',
|
||||
playerName: leaders['ast_name'],
|
||||
statValue: leaders['ast_val'].toString(),
|
||||
statLabel: 'TOTAL',
|
||||
color: const Color(0xFF2E7D32),
|
||||
icon: Icons.star,
|
||||
sf: sf, cardWidth: cardWidth, cardHeight: cardHeight,
|
||||
),
|
||||
if (isHighlighted) const Icon(Icons.star, color: Colors.amber, size: 20),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 20 * sf),
|
||||
|
||||
// Segunda Linha: Rebotes e Gráfico
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_buildStatCard(
|
||||
title: 'Rebotes',
|
||||
playerName: leaders['rbs_name'],
|
||||
statValue: leaders['rbs_val'].toString(),
|
||||
statLabel: 'TOTAL',
|
||||
color: const Color(0xFF6A1B9A),
|
||||
icon: Icons.trending_up,
|
||||
sf: sf, cardWidth: cardWidth, cardHeight: cardHeight,
|
||||
),
|
||||
SizedBox(width: 20 * sf),
|
||||
PieChartCard(
|
||||
title: 'DESEMPENHO',
|
||||
subtitle: 'Temporada',
|
||||
backgroundColor: const Color(0xFFC62828),
|
||||
onTap: () {},
|
||||
sf: sf, cardWidth: cardWidth, cardHeight: cardHeight,
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 40 * sf),
|
||||
Text('Histórico de Jogos', style: TextStyle(fontSize: 24 * sf, fontWeight: FontWeight.bold, color: Colors.grey[800])),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _calculateLeaders(List<Map<String, dynamic>> data) {
|
||||
Map<String, int> ptsMap = {};
|
||||
Map<String, int> astMap = {};
|
||||
Map<String, int> rbsMap = {};
|
||||
Map<String, String> namesMap = {}; // Aqui vamos guardar o nome real
|
||||
|
||||
for (var row in data) {
|
||||
String pid = row['member_id'].toString();
|
||||
|
||||
// 👇 BUSCA O NOME QUE VEM DA VIEW 👇
|
||||
namesMap[pid] = row['player_name']?.toString() ?? "Desconhecido";
|
||||
|
||||
ptsMap[pid] = (ptsMap[pid] ?? 0) + (row['pts'] as int? ?? 0);
|
||||
astMap[pid] = (astMap[pid] ?? 0) + (row['ast'] as int? ?? 0);
|
||||
rbsMap[pid] = (rbsMap[pid] ?? 0) + (row['rbs'] as int? ?? 0);
|
||||
}
|
||||
|
||||
// Se não houver dados, namesMap estará vazio e o reduce daria erro.
|
||||
// Por isso, se estiver vazio, retornamos logo "---".
|
||||
if (ptsMap.isEmpty) {
|
||||
return {
|
||||
'pts_name': '---', 'pts_val': 0,
|
||||
'ast_name': '---', 'ast_val': 0,
|
||||
'rbs_name': '---', 'rbs_val': 0,
|
||||
};
|
||||
}
|
||||
|
||||
String getBest(Map<String, int> map) {
|
||||
var bestId = map.entries.reduce((a, b) => a.value > b.value ? a : b).key;
|
||||
return namesMap[bestId]!;
|
||||
}
|
||||
|
||||
int getBestVal(Map<String, int> map) => map.values.reduce((a, b) => a > b ? a : b);
|
||||
|
||||
return {
|
||||
'pts_name': getBest(ptsMap), 'pts_val': getBestVal(ptsMap),
|
||||
'ast_name': getBest(astMap), 'ast_val': getBestVal(astMap),
|
||||
'rbs_name': getBest(rbsMap), 'rbs_val': getBestVal(rbsMap),
|
||||
};
|
||||
}
|
||||
|
||||
Widget _buildStatCard({
|
||||
required String title, required String playerName, required String statValue,
|
||||
required String statLabel, required Color color, required IconData icon,
|
||||
bool isHighlighted = false, required double sf, required double cardWidth, required double cardHeight,
|
||||
}) {
|
||||
return SizedBox(
|
||||
width: cardWidth, height: cardHeight,
|
||||
child: Card(
|
||||
elevation: 4,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20 * sf),
|
||||
side: isHighlighted ? const BorderSide(color: Colors.amber, width: 2) : BorderSide.none,
|
||||
),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20 * sf),
|
||||
gradient: LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [color.withOpacity(0.9), color]),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(16.0 * sf),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title.toUpperCase(), style: TextStyle(fontSize: 10 * sf, fontWeight: FontWeight.bold, color: Colors.white70)),
|
||||
Text(playerName, style: TextStyle(fontSize: 14 * sf, fontWeight: FontWeight.bold, color: Colors.white), maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
const Spacer(),
|
||||
Center(
|
||||
child: Text(statValue, style: const TextStyle(fontSize: 38, fontWeight: FontWeight.bold, color: Colors.white)),
|
||||
),
|
||||
Center(
|
||||
child: Text(statLabel, style: const TextStyle(fontSize: 12, color: Colors.white70)),
|
||||
),
|
||||
Center(child: Text(statValue, style: TextStyle(fontSize: 32 * sf, fontWeight: FontWeight.bold, color: Colors.white))),
|
||||
Center(child: Text(statLabel, style: TextStyle(fontSize: 10 * sf, color: Colors.white70))),
|
||||
const Spacer(),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
width: double.infinity, padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
decoration: BoxDecoration(color: Colors.white24, borderRadius: BorderRadius.circular(10)),
|
||||
child: const Center(child: Text('VER DETALHES', style: TextStyle(color: Colors.white, fontSize: 12))),
|
||||
child: Center(child: Text('DETALHES', style: TextStyle(color: Colors.white, fontSize: 10 * sf))),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -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),
|
||||
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user