tamanho da tela

This commit is contained in:
Diogo
2026-03-10 02:06:28 +00:00
parent f7efe47907
commit d720e09866
3 changed files with 433 additions and 312 deletions

View File

@@ -9,7 +9,7 @@ class ShotRecord {
}
class PlacarController {
final String gameId; // O ID real do jogo na base de dados
final String gameId;
final String myTeam;
final String opponentTeam;
final VoidCallback onUpdate;
@@ -22,7 +22,7 @@ class PlacarController {
});
bool isLoading = true;
bool isSaving = false; // Para mostrar o ícone de loading a guardar
bool isSaving = false;
int myScore = 0;
int opponentScore = 0;
@@ -32,8 +32,8 @@ class PlacarController {
int myTimeoutsUsed = 0;
int opponentTimeoutsUsed = 0;
String? myTeamDbId; // ID da tua equipa na BD
String? oppTeamDbId; // ID da equipa adversária na BD
String? myTeamDbId;
String? oppTeamDbId;
List<String> myCourt = [];
List<String> myBench = [];
@@ -42,7 +42,7 @@ class PlacarController {
Map<String, String> playerNumbers = {};
Map<String, Map<String, int>> playerStats = {};
Map<String, String> playerDbIds = {}; // NOVO: Mapeia o Nome do jogador -> UUID na base de dados
Map<String, String> playerDbIds = {};
bool showMyBench = false;
bool showOppBench = false;
@@ -56,58 +56,87 @@ class PlacarController {
Timer? timer;
bool isRunning = false;
Future<void> loadPlayers() async {
// --- 🔄 CARREGAMENTO COMPLETO (DADOS REAIS + ESTATÍSTICAS SALVAS) ---
Future<void> loadPlayers() async {
final supabase = Supabase.instance.client;
try {
// 1. Limpeza de segurança para evitar duplicados em "Hot Reload"
myCourt.clear(); myBench.clear(); oppCourt.clear(); oppBench.clear();
playerStats.clear(); playerNumbers.clear(); playerDbIds.clear();
myFouls = 0; opponentFouls = 0;
await Future.delayed(const Duration(milliseconds: 1500));
// 2. Buscar dados do JOGO (Placar)
final gameResponse = await supabase.from('games').select().eq('id', gameId).single();
myScore = gameResponse['my_score'] ?? 0;
opponentScore = gameResponse['opponent_score'] ?? 0;
// 1. Limpar estados para evitar duplicação
myCourt.clear();
myBench.clear();
oppCourt.clear();
oppBench.clear();
playerStats.clear();
playerNumbers.clear();
playerDbIds.clear();
myFouls = 0;
opponentFouls = 0;
// 3. Buscar IDs das Equipas
// 2. Buscar dados básicos do JOGO
final gameResponse = await supabase.from('games').select().eq('id', gameId).single();
myScore = int.tryParse(gameResponse['my_score']?.toString() ?? '0') ?? 0;
opponentScore = int.tryParse(gameResponse['opponent_score']?.toString() ?? '0') ?? 0;
int totalSeconds = int.tryParse(gameResponse['remaining_seconds']?.toString() ?? '600') ?? 600;
duration = Duration(seconds: totalSeconds);
myTimeoutsUsed = int.tryParse(gameResponse['my_timeouts']?.toString() ?? '0') ?? 0;
opponentTimeoutsUsed = int.tryParse(gameResponse['opp_timeouts']?.toString() ?? '0') ?? 0;
currentQuarter = int.tryParse(gameResponse['current_quarter']?.toString() ?? '1') ?? 1;
// 3. Buscar os IDs das equipas
final teamsResponse = await supabase.from('teams').select('id, name').inFilter('name', [myTeam, opponentTeam]);
for (var t in teamsResponse) {
if (t['name'] == myTeam) myTeamDbId = t['id'];
if (t['name'] == opponentTeam) oppTeamDbId = t['id'];
}
// 4. Buscar Membros e ESTATÍSTICAS existentes
final myPlayers = myTeamDbId != null ? await supabase.from('members').select().eq('team_id', myTeamDbId!).eq('type', 'Jogador') : [];
final oppPlayers = oppTeamDbId != null ? await supabase.from('members').select().eq('team_id', oppTeamDbId!).eq('type', 'Jogador') : [];
// Buscar todas as stats deste jogo de uma vez
// 4. Buscar os Jogadores
List<dynamic> myPlayers = myTeamDbId != null ? await supabase.from('members').select().eq('team_id', myTeamDbId!).eq('type', 'Jogador') : [];
List<dynamic> oppPlayers = oppTeamDbId != null ? await supabase.from('members').select().eq('team_id', oppTeamDbId!).eq('type', 'Jogador') : [];
// 5. BUSCAR ESTATÍSTICAS JÁ SALVAS
final statsResponse = await supabase.from('player_stats').select().eq('game_id', gameId);
final Map<String, dynamic> savedStatsMap = {
for (var s in statsResponse) s['member_id'].toString(): s
final Map<String, dynamic> savedStats = {
for (var item in statsResponse) item['member_id'].toString(): item
};
// 5. Processar Minha Equipa
// 6. Registar a tua equipa
for (int i = 0; i < myPlayers.length; i++) {
String dbId = myPlayers[i]['id'].toString();
String name = myPlayers[i]['name'].toString();
_registerPlayer(name: name, number: myPlayers[i]['number']?.toString() ?? "0", dbId: dbId, isMyTeam: true, isCourt: i < 5);
if (savedStatsMap.containsKey(dbId)) {
_injectStats(name, savedStatsMap[dbId], true);
_registerPlayer(name: name, number: myPlayers[i]['number']?.toString() ?? "0", dbId: dbId, isMyTeam: true, isCourt: i < 5);
if (savedStats.containsKey(dbId)) {
var s = savedStats[dbId];
playerStats[name] = {
"pts": s['pts'] ?? 0, "rbs": s['rbs'] ?? 0, "ast": s['ast'] ?? 0,
"stl": s['stl'] ?? 0, "tov": s['tov'] ?? 0, "blk": s['blk'] ?? 0,
"fls": s['fls'] ?? 0, "fgm": s['fgm'] ?? 0, "fga": s['fga'] ?? 0,
};
myFouls += (s['fls'] as int? ?? 0);
}
}
_padTeam(myCourt, myBench, "Jogador", isMyTeam: true);
// 6. Processar Adversário
// 7. Registar a equipa adversária
for (int i = 0; i < oppPlayers.length; i++) {
String dbId = oppPlayers[i]['id'].toString();
String name = oppPlayers[i]['name'].toString();
_registerPlayer(name: name, number: oppPlayers[i]['number']?.toString() ?? "0", dbId: dbId, isMyTeam: false, isCourt: i < 5);
if (savedStatsMap.containsKey(dbId)) {
_injectStats(name, savedStatsMap[dbId], false);
if (savedStats.containsKey(dbId)) {
var s = savedStats[dbId];
playerStats[name] = {
"pts": s['pts'] ?? 0, "rbs": s['rbs'] ?? 0, "ast": s['ast'] ?? 0,
"stl": s['stl'] ?? 0, "tov": s['tov'] ?? 0, "blk": s['blk'] ?? 0,
"fls": s['fls'] ?? 0, "fgm": s['fgm'] ?? 0, "fga": s['fga'] ?? 0,
};
opponentFouls += (s['fls'] as int? ?? 0);
}
}
_padTeam(oppCourt, oppBench, "Adversário", isMyTeam: false);
@@ -115,29 +144,18 @@ class PlacarController {
isLoading = false;
onUpdate();
} catch (e) {
debugPrint("Erro ao carregar: $e");
debugPrint("Erro ao retomar jogo: $e");
_padTeam(myCourt, myBench, "Falha", isMyTeam: true);
_padTeam(oppCourt, oppBench, "Falha Opp", isMyTeam: false);
isLoading = false;
onUpdate();
}
}
// Função auxiliar para injetar os dados salvos
void _injectStats(String playerName, Map<String, dynamic> s, bool isMyTeam) {
playerStats[playerName] = {
"pts": s['pts'] ?? 0, "rbs": s['rbs'] ?? 0, "ast": s['ast'] ?? 0,
"stl": s['stl'] ?? 0, "tov": s['tov'] ?? 0, "blk": s['blk'] ?? 0,
"fls": s['fls'] ?? 0, "fgm": s['fgm'] ?? 0, "fga": s['fga'] ?? 0,
};
if (isMyTeam) myFouls += (s['fls'] as int? ?? 0);
else opponentFouls += (s['fls'] as int? ?? 0);
}
void _registerPlayer({required String name, required String number, String? dbId, required bool isMyTeam, required bool isCourt}) {
if (playerNumbers.containsKey(name)) name = "$name (Opp)";
playerNumbers[name] = number;
if (dbId != null) playerDbIds[name] = dbId; // Só guarda na lista de IDs se for um jogador real da BD
if (dbId != null) playerDbIds[name] = dbId;
playerStats[name] = {"pts": 0, "rbs": 0, "ast": 0, "stl": 0, "tov": 0, "blk": 0, "fls": 0, "fgm": 0, "fga": 0};
if (isMyTeam) {
@@ -154,7 +172,6 @@ class PlacarController {
}
// --- TEMPO E TIMEOUTS ---
// (Mantive o teu código original igualzinho aqui)
void toggleTimer(BuildContext context) {
if (isRunning) {
timer?.cancel();
@@ -195,7 +212,7 @@ class PlacarController {
String formatTime() => "${duration.inMinutes.toString().padLeft(2, '0')}:${duration.inSeconds.remainder(60).toString().padLeft(2, '0')}";
// --- LÓGICA DE JOGO ---
// --- LÓGICA DE JOGO & VALIDAÇÃO GEOMÉTRICA DE ZONAS ---
void handleActionDrag(BuildContext context, String action, String playerData) {
String name = playerData.replaceAll("player_my_", "").replaceAll("player_opp_", "");
final stats = playerStats[name]!;
@@ -239,16 +256,66 @@ class PlacarController {
onUpdate();
}
void registerShotLocation(Offset position) {
// AGORA RECEBE CONTEXT E SIZE PARA A MATEMÁTICA
void registerShotLocation(BuildContext context, Offset position, Size size) {
if (pendingAction == null || pendingPlayer == null) return;
bool is3Pt = pendingAction!.contains("_3");
bool is2Pt = pendingAction!.contains("_2");
// Validação
if (is3Pt || is2Pt) {
bool isValid = _validateShotZone(position, size, is3Pt);
if (!isValid) {
// Se a validação falhar, fudeo. Bloqueia.
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('🛑 Vai dar merda! Local de lançamento incompatível com a pontuação.'),
backgroundColor: Colors.red,
duration: Duration(seconds: 2),
)
);
return; // Aborta!
}
}
bool isMake = pendingAction!.startsWith("add_pts_");
matchShots.add(ShotRecord(position, isMake));
commitStat(pendingAction!, pendingPlayer!);
isSelectingShotLocation = false;
pendingAction = null;
pendingPlayer = null;
onUpdate();
}
// A MATEMÁTICA DA ZONA
bool _validateShotZone(Offset pos, Size size, bool is3Pt) {
double w = size.width;
double h = size.height;
// Ajusta o 0.12 e 0.88 se os teus cestos na imagem estiverem mais para o lado
Offset leftHoop = Offset(w * 0.12, h * 0.5);
Offset rightHoop = Offset(w * 0.88, h * 0.5);
// O raio da linha de 3 pontos (Brinca com este 0.28 se a área ficar muito grande ou pequena)
double threePointRadius = w * 0.28;
Offset activeHoop = pos.dx < w / 2 ? leftHoop : rightHoop;
double distanceToHoop = (pos - activeHoop).distance;
// Zonas de canto (onde a linha de 3 é reta)
bool isCorner3 = (pos.dy < h * 0.15 || pos.dy > h * 0.85) &&
(pos.dx < w * 0.20 || pos.dx > w * 0.80);
if (is3Pt) {
return distanceToHoop >= threePointRadius || isCorner3;
} else {
return distanceToHoop < threePointRadius && !isCorner3;
}
}
void cancelShotLocation() {
isSelectingShotLocation = false;
pendingAction = null;
@@ -296,25 +363,25 @@ class PlacarController {
// --- 💾 FUNÇÃO PARA GUARDAR DADOS NA BD ---
Future<void> saveGameStats(BuildContext context) async {
final supabase = Supabase.instance.client;
isSaving = true;
onUpdate();
try {
// 1. Atualizar o resultado final na tabela 'games'
await supabase.from('games').update({
'my_score': myScore,
'opponent_score': opponentScore,
'remaining_seconds': duration.inSeconds,
'my_timeouts': myTimeoutsUsed,
'opp_timeouts': opponentTimeoutsUsed,
'current_quarter': currentQuarter,
'status': currentQuarter >= 4 && duration.inSeconds == 0 ? 'Terminado' : 'Pausado',
}).eq('id', gameId);
// 2. Preparar a lista de estatísticas individuais
List<Map<String, dynamic>> batchStats = [];
playerStats.forEach((playerName, stats) {
String? memberDbId = playerDbIds[playerName]; // Vai buscar o UUID real do jogador
String? memberDbId = playerDbIds[playerName];
// Só guarda se for um jogador real (com ID) e se tiver feito ALGUMA coisa (pontos, faltas, etc)
if (memberDbId != null && stats.values.any((val) => val > 0)) {
bool isMyTeamPlayer = myCourt.contains(playerName) || myBench.contains(playerName);
String teamId = isMyTeamPlayer ? myTeamDbId! : oppTeamDbId!;
@@ -336,10 +403,8 @@ class PlacarController {
}
});
// 3. Apagar stats antigas deste jogo para não haver duplicados caso cliques no botão "Guardar" 2 vezes
await supabase.from('player_stats').delete().eq('game_id', gameId);
// 4. Inserir as novas estatísticas de todos os jogadores de uma vez
if (batchStats.isNotEmpty) {
await supabase.from('player_stats').insert(batchStats);
}

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:playmaker/controllers/placar_controller.dart';
import 'package:playmaker/widgets/placar_widgets.dart';
import 'dart:math' as math;
class PlacarPage extends StatefulWidget {
final String gameId, myTeam, opponentTeam;
@@ -17,7 +18,10 @@ class _PlacarPageState extends State<PlacarPage> {
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight, DeviceOrientation.landscapeLeft]);
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
_controller = PlacarController(
gameId: widget.gameId,
@@ -37,8 +41,8 @@ class _PlacarPageState extends State<PlacarPage> {
super.dispose();
}
// Função auxiliar para criar o botão de arrastar faltas que não está no painel inferior
Widget _buildFloatingFoulBtn(String label, Color color, String action, IconData icon, double left, double right, double top, double h) {
// --- BOTÕES FLUTUANTES DE FALTA (MUITO MAIS PEQUENOS AQUI 👇) ---
Widget _buildFloatingFoulBtn(String label, Color color, String action, IconData icon, double left, double right, double top, double sf) {
return Positioned(
top: top,
left: left > 0 ? left : null,
@@ -47,160 +51,216 @@ class _PlacarPageState extends State<PlacarPage> {
data: action,
feedback: Material(
color: Colors.transparent,
child: CircleAvatar(radius: 30, backgroundColor: color.withOpacity(0.8), child: Icon(icon, color: Colors.white)),
child: CircleAvatar(
radius: 25 * sf, // Era 35
backgroundColor: color.withOpacity(0.8),
child: Icon(icon, color: Colors.white, size: 25 * sf) // Era 35
),
),
child: Column(
children: [
CircleAvatar(
radius: 25,
radius: 22 * sf, // Era 30
backgroundColor: color,
child: Icon(icon, color: Colors.white, size: 30),
child: Icon(icon, color: Colors.white, size: 26 * sf), // Era 35
),
Text(label, style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 12)),
SizedBox(height: 4 * sf),
Text(label, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 11 * sf)), // Era 14
],
),
),
);
}
// --- BOTÕES LATERAIS QUADRADOS ---
Widget _buildCornerBtn({required String heroTag, required IconData icon, required Color color, required VoidCallback onTap, required double size, bool isLoading = false}) {
return SizedBox(
width: size,
height: size,
child: FloatingActionButton(
heroTag: heroTag,
backgroundColor: color,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12 * (size / 50))),
elevation: 4,
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),
),
);
}
@override
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);
final double cornerBtnSize = 50 * sf;
if (_controller.isLoading) {
return const Scaffold(
backgroundColor: Color(0xFF266174),
body: Center(child: CircularProgressIndicator(color: Colors.white)),
return Scaffold(
backgroundColor: const Color(0xFF16202C),
body: Center(
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),
StreamBuilder(
stream: Stream.periodic(const Duration(seconds: 3)),
builder: (context, snapshot) {
List<String> frases = [
"O Treinador está a desenhar a tática...",
"A encher as bolas com ar de campeão...",
"O árbitro está a testar o apito...",
"A verificar se o cesto está nivelado...",
"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 Scaffold(
backgroundColor: const Color(0xFF266174),
body: Stack(
children: [
Container(
margin: const EdgeInsets.only(left: 60, right: 60, bottom: 50),
decoration: BoxDecoration(border: Border.all(color: Colors.white, width: 2.0)),
child: LayoutBuilder(
builder: (context, constraints) {
final w = constraints.maxWidth;
final h = constraints.maxHeight;
body: SafeArea(
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)),
child: LayoutBuilder(
builder: (context, constraints) {
final w = constraints.maxWidth;
final h = constraints.maxHeight;
return Stack(
children: [
// --- MAPA DO CAMPO ---
GestureDetector(
onTapDown: (details) {
if (_controller.isSelectingShotLocation) _controller.registerShotLocation(details.localPosition);
},
child: Container(
decoration: const BoxDecoration(
image: DecorationImage(image: AssetImage('assets/campo.png'), fit: BoxFit.cover, alignment: Alignment(0.0, 0.2)),
),
child: Stack(
children: _controller.matchShots.map((shot) => Positioned(
left: shot.position.dx - 8, top: shot.position.dy - 8,
child: CircleAvatar(radius: 8, backgroundColor: shot.isMake ? Colors.green : Colors.red, child: Icon(shot.isMake ? Icons.check : Icons.close, size: 10, color: Colors.white)),
)).toList(),
return Stack(
children: [
GestureDetector(
onTapDown: (details) {
if (_controller.isSelectingShotLocation) {
_controller.registerShotLocation(context, details.localPosition, Size(w, h));
}
},
child: Container(
decoration: const BoxDecoration(
image: DecorationImage(image: AssetImage('assets/campo.png'), fit: BoxFit.cover, alignment: Alignment(0.0, 0.2)),
),
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)),
)).toList(),
),
),
),
),
// --- JOGADORES EM CAMPO ---
if (!_controller.isSelectingShotLocation) ...[
Positioned(top: h * 0.25, left: w * 0.02, child: PlayerCourtCard(controller: _controller, name: _controller.myCourt[0], isOpponent: false)),
Positioned(top: h * 0.68, left: w * 0.02, child: PlayerCourtCard(controller: _controller, name: _controller.myCourt[1], isOpponent: false)),
Positioned(top: h * 0.45, left: w * 0.25, child: PlayerCourtCard(controller: _controller, name: _controller.myCourt[2], isOpponent: false)),
Positioned(top: h * 0.15, left: w * 0.20, child: PlayerCourtCard(controller: _controller, name: _controller.myCourt[3], isOpponent: false)),
Positioned(top: h * 0.80, left: w * 0.20, child: PlayerCourtCard(controller: _controller, name: _controller.myCourt[4], isOpponent: false)),
// --- JOGADORES ---
if (!_controller.isSelectingShotLocation) ...[
Positioned(top: h * 0.25, left: w * 0.02, child: PlayerCourtCard(controller: _controller, name: _controller.myCourt[0], isOpponent: false, sf: sf)),
Positioned(top: h * 0.68, left: w * 0.02, child: PlayerCourtCard(controller: _controller, name: _controller.myCourt[1], isOpponent: false, sf: sf)),
Positioned(top: h * 0.45, left: w * 0.25, child: PlayerCourtCard(controller: _controller, name: _controller.myCourt[2], isOpponent: false, sf: sf)),
Positioned(top: h * 0.15, left: w * 0.20, child: PlayerCourtCard(controller: _controller, name: _controller.myCourt[3], isOpponent: false, sf: sf)),
Positioned(top: h * 0.80, left: w * 0.20, child: PlayerCourtCard(controller: _controller, name: _controller.myCourt[4], isOpponent: false, sf: sf)),
Positioned(top: h * 0.25, right: w * 0.02, child: PlayerCourtCard(controller: _controller, name: _controller.oppCourt[0], isOpponent: true, sf: sf)),
Positioned(top: h * 0.68, right: w * 0.02, child: PlayerCourtCard(controller: _controller, name: _controller.oppCourt[1], isOpponent: true, sf: sf)),
Positioned(top: h * 0.45, right: w * 0.25, child: PlayerCourtCard(controller: _controller, name: _controller.oppCourt[2], isOpponent: true, sf: sf)),
Positioned(top: h * 0.15, right: w * 0.20, child: PlayerCourtCard(controller: _controller, name: _controller.oppCourt[3], isOpponent: true, sf: sf)),
Positioned(top: h * 0.80, right: w * 0.20, child: PlayerCourtCard(controller: _controller, name: _controller.oppCourt[4], isOpponent: true, sf: sf)),
],
// --- 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),
],
// --- 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)),
),
),
),
// --- PLACAR NO TOPO ---
Positioned(top: 0, left: 0, right: 0, child: Center(child: TopScoreboard(controller: _controller, sf: sf))),
Positioned(top: h * 0.25, right: w * 0.02, child: PlayerCourtCard(controller: _controller, name: _controller.oppCourt[0], isOpponent: true)),
Positioned(top: h * 0.68, right: w * 0.02, child: PlayerCourtCard(controller: _controller, name: _controller.oppCourt[1], isOpponent: true)),
Positioned(top: h * 0.45, right: w * 0.25, child: PlayerCourtCard(controller: _controller, name: _controller.oppCourt[2], isOpponent: true)),
Positioned(top: h * 0.15, right: w * 0.20, child: PlayerCourtCard(controller: _controller, name: _controller.oppCourt[3], isOpponent: true)),
Positioned(top: h * 0.80, right: w * 0.20, child: PlayerCourtCard(controller: _controller, name: _controller.oppCourt[4], isOpponent: true)),
],
// --- BOTÕES DE AÇÃO ---
if (!_controller.isSelectingShotLocation) Positioned(bottom: 10 * sf, left: 0, right: 0, child: ActionButtonsPanel(controller: _controller, sf: sf)),
// --- BOTÕES DE FALTA (FLUTUANTES) ---
// Estes são os botões que você pediu, posicionados em relação ao centro
if (!_controller.isSelectingShotLocation) ...[
_buildFloatingFoulBtn("FALTA +", Colors.orange, "add_foul", Icons.sports, w * 0.38, 0, h * 0.30, h),
_buildFloatingFoulBtn("FALTA -", Colors.redAccent, "sub_foul", Icons.block, 0, w * 0.38, h * 0.30, h),
],
// --- BOTÃO CENTRAL DO TEMPO ---
if (!_controller.isSelectingShotLocation)
Positioned(
top: (h * 0.30) + 70, left: 0, right: 0,
child: Center(
child: GestureDetector(
onTap: () => _controller.toggleTimer(context),
child: CircleAvatar(radius: 60, backgroundColor: Colors.grey.withOpacity(0.5), child: Icon(_controller.isRunning ? Icons.pause : Icons.play_arrow, color: Colors.white, size: 50)),
// --- OVERLAY LANÇAMENTO ---
if (_controller.isSelectingShotLocation)
Positioned(
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)),
),
),
),
),
],
);
},
),
),
// --- PLACAR E BOTÕES DE AÇÃO ---
Positioned(top: 0, left: 0, right: 0, child: Center(child: TopScoreboard(controller: _controller))),
if (!_controller.isSelectingShotLocation) Positioned(bottom: 10, left: 0, right: 0, child: ActionButtonsPanel(controller: _controller)),
// --- OVERLAY DE MARCAÇÃO DE LANÇAMENTO ---
if (_controller.isSelectingShotLocation)
Positioned(
top: h * 0.4, left: 0, right: 0,
child: Center(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
decoration: BoxDecoration(color: Colors.black87, borderRadius: BorderRadius.circular(10), border: Border.all(color: Colors.white)),
child: const Text("TOQUE NO CAMPO PARA MARCAR O LOCAL DO LANÇAMENTO", style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold)),
),
),
),
// --- 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)),
],
);
},
),
),
// --- MENUS LATERAIS E BANCOS DE SUPLENTES ---
if (!_controller.isSelectingShotLocation) ...[
Positioned(
top: 20, left: 10,
child: FloatingActionButton(
heroTag: 'btn_save',
backgroundColor: const Color(0xFF16202C),
mini: true,
onPressed: _controller.isSaving ? null : () => _controller.saveGameStats(context),
child: _controller.isSaving
? const SizedBox(width: 15, height: 15, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2))
: const Icon(Icons.save, color: Colors.white)
)
),
Positioned(top: 70, left: 10, child: FloatingActionButton(heroTag: 'btn_exit', backgroundColor: const Color(0xFFD92C2C), mini: true, onPressed: () => Navigator.pop(context), child: const Icon(Icons.exit_to_app, color: Colors.white))),
Positioned(
bottom: 50, left: 10,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (_controller.showMyBench) BenchPlayersList(controller: _controller, isOpponent: false),
const SizedBox(height: 10),
FloatingActionButton(heroTag: 'btn_sub_home', backgroundColor: const Color(0xFF1E5BB2), mini: true, onPressed: () { _controller.showMyBench = !_controller.showMyBench; _controller.onUpdate(); }, child: const Icon(Icons.swap_horiz, color: Colors.white)),
],
)
),
),
Positioned(
bottom: 50, right: 10,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (_controller.showOppBench) BenchPlayersList(controller: _controller, isOpponent: true),
const SizedBox(height: 10),
FloatingActionButton(heroTag: 'btn_sub_away', backgroundColor: const Color(0xFFD92C2C), mini: true, onPressed: () { _controller.showOppBench = !_controller.showOppBench; _controller.onUpdate(); }, child: const Icon(Icons.swap_horiz, color: Colors.white)),
],
// Base Esquerda: Banco Casa
Positioned(
bottom: 50 * sf, left: 10 * 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(); })
],
),
),
),
// Base Direita: Banco Visitante
Positioned(
bottom: 50 * sf, right: 10 * 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(); })
],
),
),
],
],
],
),
),
);
}

View File

@@ -4,70 +4,73 @@ import 'package:playmaker/controllers/placar_controller.dart';
// --- PLACAR SUPERIOR ---
class TopScoreboard extends StatelessWidget {
final PlacarController controller;
const TopScoreboard({super.key, required this.controller});
final double sf;
const TopScoreboard({super.key, required this.controller, required this.sf});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 30),
padding: EdgeInsets.symmetric(vertical: 8 * sf, horizontal: 30 * sf),
decoration: BoxDecoration(
color: const Color(0xFF16202C),
borderRadius: const BorderRadius.only(bottomLeft: Radius.circular(15), bottomRight: Radius.circular(15)),
border: Border.all(color: Colors.white, width: 2),
color: const Color(0xFF16202C),
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(20 * sf), bottomRight: Radius.circular(20 * sf)),
border: Border.all(color: Colors.white, width: 2 * sf),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
_buildTeamSection(controller.myTeam, controller.myScore, controller.myFouls, controller.myTimeoutsUsed, const Color(0xFF1E5BB2), false),
const SizedBox(width: 25),
_buildTeamSection(controller.myTeam, controller.myScore, controller.myFouls, controller.myTimeoutsUsed, const Color(0xFF1E5BB2), false, sf),
SizedBox(width: 25 * sf),
Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 6),
decoration: BoxDecoration(color: const Color(0xFF2C3E50), borderRadius: BorderRadius.circular(6)),
child: Text(controller.formatTime(), style: const TextStyle(color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold, fontFamily: 'monospace')),
padding: EdgeInsets.symmetric(horizontal: 16 * sf, vertical: 4 * sf),
decoration: BoxDecoration(color: const Color(0xFF2C3E50), borderRadius: BorderRadius.circular(8 * sf)),
child: Text(controller.formatTime(), style: TextStyle(color: Colors.white, fontSize: 26 * sf, fontWeight: FontWeight.w900, fontFamily: 'monospace', letterSpacing: 2 * sf)),
),
const SizedBox(height: 5),
Text("PERÍODO ${controller.currentQuarter}", style: const TextStyle(color: Colors.orangeAccent, fontSize: 14, fontWeight: FontWeight.bold)),
SizedBox(height: 4 * sf),
Text("PERÍODO ${controller.currentQuarter}", style: TextStyle(color: Colors.orangeAccent, fontSize: 13 * sf, fontWeight: FontWeight.w900)),
],
),
const SizedBox(width: 25),
_buildTeamSection(controller.opponentTeam, controller.opponentScore, controller.opponentFouls, controller.opponentTimeoutsUsed, const Color(0xFFD92C2C), true),
SizedBox(width: 25 * sf),
_buildTeamSection(controller.opponentTeam, controller.opponentScore, controller.opponentFouls, controller.opponentTimeoutsUsed, const Color(0xFFD92C2C), true, sf),
],
),
);
}
Widget _buildTeamSection(String name, int score, int fouls, int timeouts, Color color, bool isOpp) {
Widget _buildTeamSection(String name, int score, int fouls, int timeouts, Color color, bool isOpp, double sf) {
final timeoutIndicators = Row(
mainAxisSize: MainAxisSize.min,
children: List.generate(3, (index) => Container(
margin: const EdgeInsets.symmetric(horizontal: 3),
width: 12, height: 12,
decoration: BoxDecoration(shape: BoxShape.circle, color: index < timeouts ? Colors.yellow : Colors.grey.shade600, border: Border.all(color: Colors.black26)),
margin: EdgeInsets.symmetric(horizontal: 3 * sf),
width: 10 * sf, height: 10 * sf,
decoration: BoxDecoration(shape: BoxShape.circle, color: index < timeouts ? Colors.yellow : Colors.grey.shade600, border: Border.all(color: Colors.white54, width: 1.5 * sf)),
)),
);
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: isOpp
? [
Column(children: [_scoreBox(score, color), const SizedBox(height: 4), Text("FALTAS: $fouls", style: TextStyle(color: fouls >= 5 ? Colors.red : Colors.yellowAccent, fontSize: 12, fontWeight: FontWeight.bold)), timeoutIndicators]),
const SizedBox(width: 15),
Text(name.toUpperCase(), style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold))
]
: [
Text(name.toUpperCase(), style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(width: 15),
Column(children: [_scoreBox(score, color), const SizedBox(height: 4), Text("FALTAS: $fouls", style: TextStyle(color: fouls >= 5 ? Colors.red : Colors.yellowAccent, fontSize: 12, fontWeight: FontWeight.bold)), timeoutIndicators])
]
);
List<Widget> content = [
Column(children: [_scoreBox(score, color, sf), SizedBox(height: 6 * sf), timeoutIndicators]),
SizedBox(width: 15 * sf),
Column(
crossAxisAlignment: isOpp ? CrossAxisAlignment.start : CrossAxisAlignment.end,
children: [
Text(name.toUpperCase(), style: TextStyle(color: Colors.white, fontSize: 18 * sf, fontWeight: FontWeight.w900, letterSpacing: 1 * sf)),
SizedBox(height: 4 * sf),
Text("FALTAS: $fouls", style: TextStyle(color: fouls >= 5 ? Colors.redAccent : Colors.yellowAccent, fontSize: 12 * sf, fontWeight: FontWeight.bold)),
],
)
];
return Row(crossAxisAlignment: CrossAxisAlignment.center, children: isOpp ? content : content.reversed.toList());
}
Widget _scoreBox(int score, Color color) => Container(
width: 50, height: 40,
Widget _scoreBox(int score, Color color, double sf) => Container(
width: 50 * sf, height: 40 * sf,
alignment: Alignment.center,
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(6)),
child: Text(score.toString(), style: const TextStyle(color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold)),
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(6 * sf)),
child: Text(score.toString(), style: TextStyle(color: Colors.white, fontSize: 24 * sf, fontWeight: FontWeight.w900)),
);
}
@@ -75,7 +78,8 @@ class TopScoreboard extends StatelessWidget {
class BenchPlayersList extends StatelessWidget {
final PlacarController controller;
final bool isOpponent;
const BenchPlayersList({super.key, required this.controller, required this.isOpponent});
final double sf;
const BenchPlayersList({super.key, required this.controller, required this.isOpponent, required this.sf});
@override
Widget build(BuildContext context) {
@@ -91,24 +95,23 @@ class BenchPlayersList extends StatelessWidget {
final bool isFouledOut = fouls >= 5;
Widget avatarUI = Container(
margin: const EdgeInsets.only(bottom: 5),
margin: EdgeInsets.only(bottom: 6 * sf),
decoration: BoxDecoration(shape: BoxShape.circle, border: Border.all(color: Colors.white, width: 1.5 * sf), boxShadow: [BoxShadow(color: Colors.black45, blurRadius: 4 * sf, offset: Offset(0, 2 * sf))]),
child: CircleAvatar(
backgroundColor: isFouledOut ? Colors.grey.shade700 : teamColor,
child: Text(num, style: TextStyle(color: isFouledOut ? Colors.red.shade300 : Colors.white, fontSize: 14, decoration: isFouledOut ? TextDecoration.lineThrough : TextDecoration.none)),
radius: 20 * sf,
backgroundColor: isFouledOut ? Colors.grey.shade800 : teamColor,
child: Text(num, style: TextStyle(color: isFouledOut ? Colors.red.shade300 : Colors.white, fontSize: 14 * sf, fontWeight: FontWeight.bold, decoration: isFouledOut ? TextDecoration.lineThrough : TextDecoration.none)),
),
);
if (isFouledOut) {
return GestureDetector(
onTap: () => ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('🛑 $playerName não pode voltar (Expulso).'), backgroundColor: Colors.red)),
child: avatarUI,
);
return GestureDetector(onTap: () => ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('🛑 $playerName não pode voltar (Expulso).'), backgroundColor: Colors.red)), child: avatarUI);
}
return Draggable<String>(
data: "$prefix$playerName",
feedback: Material(color: Colors.transparent, child: CircleAvatar(backgroundColor: teamColor, child: Text(num, style: const TextStyle(color: Colors.white)))),
childWhenDragging: const Opacity(opacity: 0.5, child: SizedBox(width: 40, height: 40)),
feedback: Material(color: Colors.transparent, child: CircleAvatar(radius: 25 * sf, backgroundColor: teamColor, child: Text(num, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 16 * sf)))),
childWhenDragging: Opacity(opacity: 0.5, child: SizedBox(width: 40 * sf, height: 40 * sf)),
child: avatarUI,
);
}).toList(),
@@ -121,8 +124,9 @@ class PlayerCourtCard extends StatelessWidget {
final PlacarController controller;
final String name;
final bool isOpponent;
final double sf;
const PlayerCourtCard({super.key, required this.controller, required this.name, required this.isOpponent});
const PlayerCourtCard({super.key, required this.controller, required this.name, required this.isOpponent, required this.sf});
@override
Widget build(BuildContext context) {
@@ -136,36 +140,31 @@ class PlayerCourtCard extends StatelessWidget {
feedback: Material(
color: Colors.transparent,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
decoration: BoxDecoration(color: teamColor.withOpacity(0.9), borderRadius: BorderRadius.circular(8)),
child: Text(name, style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold)),
padding: EdgeInsets.symmetric(horizontal: 16 * sf, vertical: 10 * sf),
decoration: BoxDecoration(color: teamColor.withOpacity(0.9), borderRadius: BorderRadius.circular(8 * sf)),
child: Text(name, style: TextStyle(color: Colors.white, fontSize: 18 * sf, fontWeight: FontWeight.bold)),
),
),
childWhenDragging: Opacity(opacity: 0.5, child: _playerCardUI(number, name, stats, teamColor, false, false)),
childWhenDragging: Opacity(opacity: 0.5, child: _playerCardUI(number, name, stats, teamColor, false, false, sf)),
child: DragTarget<String>(
onAcceptWithDetails: (details) {
final action = details.data;
if (action.startsWith("add_") || action.startsWith("sub_") || action.startsWith("miss_")) {
controller.handleActionDrag(context, action, "$prefix$name");
}
else if (action.startsWith("bench_")) {
controller.handleSubbing(context, action, name, isOpponent);
}
if (action.startsWith("add_") || action.startsWith("sub_") || action.startsWith("miss_")) controller.handleActionDrag(context, action, "$prefix$name");
else if (action.startsWith("bench_")) controller.handleSubbing(context, action, name, isOpponent);
},
builder: (context, candidateData, rejectedData) {
bool isSubbing = candidateData.any((data) => data != null && (data.startsWith("bench_my_") || data.startsWith("bench_opp_")));
bool isActionHover = candidateData.any((data) => data != null && (data.startsWith("add_") || data.startsWith("sub_") || data.startsWith("miss_")));
return _playerCardUI(number, name, stats, teamColor, isSubbing, isActionHover);
return _playerCardUI(number, name, stats, teamColor, isSubbing, isActionHover, sf);
},
),
);
}
Widget _playerCardUI(String number, String name, Map<String, int> stats, Color teamColor, bool isSubbing, bool isActionHover) {
Widget _playerCardUI(String number, String name, Map<String, int> stats, Color teamColor, bool isSubbing, bool isActionHover, double sf) {
bool isFouledOut = stats["fls"]! >= 5;
Color bgColor = isFouledOut ? Colors.red.shade100 : Colors.white;
Color bgColor = isFouledOut ? Colors.red.shade50 : Colors.white;
Color borderColor = isFouledOut ? Colors.redAccent : Colors.transparent;
if (isSubbing) { bgColor = Colors.blue.shade50; borderColor = Colors.blue; }
else if (isActionHover && !isFouledOut) { bgColor = Colors.orange.shade50; borderColor = Colors.orange; }
@@ -175,29 +174,30 @@ class PlayerCourtCard extends StatelessWidget {
String displayName = name.length > 12 ? "${name.substring(0, 10)}..." : name;
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: bgColor, borderRadius: BorderRadius.circular(12), border: Border.all(color: borderColor, width: 2),
boxShadow: const [BoxShadow(color: Colors.black26, blurRadius: 6, offset: Offset(0, 3))],
color: bgColor,
borderRadius: BorderRadius.circular(8 * sf),
border: Border.all(color: borderColor, width: 2 * sf),
boxShadow: [BoxShadow(color: Colors.black45, blurRadius: 4 * sf, offset: Offset(2 * sf, 3 * sf))],
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 40, height: 40,
decoration: BoxDecoration(color: isFouledOut ? Colors.grey : teamColor, borderRadius: BorderRadius.circular(8)),
alignment: Alignment.center,
child: Text(number, style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold)),
padding: EdgeInsets.symmetric(horizontal: 10 * sf, vertical: 12 * sf),
decoration: BoxDecoration(color: isFouledOut ? Colors.grey[700] : teamColor, borderRadius: BorderRadius.horizontal(left: Radius.circular(6 * sf))),
child: Text(number, style: TextStyle(color: Colors.white, fontSize: 18 * sf, fontWeight: FontWeight.w900)),
),
const SizedBox(width: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min,
children: [
Text(displayName, style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: isFouledOut ? Colors.red : Colors.black87, decoration: isFouledOut ? TextDecoration.lineThrough : TextDecoration.none)),
const SizedBox(height: 1),
Text("${stats["pts"]} Pts | FG: $fgm/$fga ($fgPercent%)", style: TextStyle(fontSize: 11, color: isFouledOut ? Colors.red : Colors.grey[700], fontWeight: FontWeight.w600)),
Text("${stats["ast"]} Ast | ${stats["rbs"]} Rbs | ${stats["fls"]} Fls", style: TextStyle(fontSize: 11, color: isFouledOut ? Colors.red : Colors.grey, fontWeight: FontWeight.w500)),
],
Padding(
padding: EdgeInsets.symmetric(horizontal: 8 * sf, vertical: 4 * sf),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min,
children: [
Text(displayName, style: TextStyle(fontSize: 14 * sf, fontWeight: FontWeight.bold, color: isFouledOut ? Colors.red : Colors.black87, decoration: isFouledOut ? TextDecoration.lineThrough : TextDecoration.none)),
Text("${stats["pts"]} Pts | FG: $fgm/$fga ($fgPercent%)", style: TextStyle(fontSize: 10 * sf, color: isFouledOut ? Colors.red : Colors.grey[800], fontWeight: FontWeight.bold)),
Text("${stats["ast"]} Ast | ${stats["rbs"]} Rbs | ${stats["fls"]} Fls", style: TextStyle(fontSize: 10 * sf, color: isFouledOut ? Colors.red : Colors.grey[600], fontWeight: FontWeight.w600)),
],
),
),
],
),
@@ -205,83 +205,80 @@ class PlayerCourtCard extends StatelessWidget {
}
}
// --- PAINEL DE BOTÕES DE AÇÃO ---
// --- PAINEL DE BOTÕES DE AÇÃO (PONTO REBUÇADO) ---
class ActionButtonsPanel extends StatelessWidget {
final PlacarController controller;
const ActionButtonsPanel({super.key, required this.controller});
final double sf;
const ActionButtonsPanel({super.key, required this.controller, required this.sf});
@override
Widget build(BuildContext context) {
// Aumentei ligeiramente o tamanho dos botões de ação face ao último código!
final double baseSize = 56 * sf; // Era 48 (inicialmente 65)
final double feedSize = 70 * sf; // Era 60 (inicialmente 80)
final double gap = 10 * sf;
return Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
_columnBtn([
_actionBtn("T.O", const Color(0xFF1E5BB2), () => controller.useTimeout(false), labelSize: 20),
_dragAndTargetBtn("1", Colors.orange, "add_pts_1"),
_dragAndTargetBtn("1", Colors.orange, "sub_pts_1", isX: true),
_dragAndTargetBtn("STL", Colors.green, "add_stl"),
]),
const SizedBox(width: 15),
_actionBtn("T.O", const Color(0xFF1E5BB2), () => controller.useTimeout(false), baseSize, feedSize, sf),
_dragAndTargetBtn("1", Colors.orange, "add_pts_1", baseSize, feedSize, sf),
_dragAndTargetBtn("1", Colors.orange, "sub_pts_1", baseSize, feedSize, sf, isX: true),
_dragAndTargetBtn("STL", Colors.green, "add_stl", baseSize, feedSize, sf),
], gap),
SizedBox(width: gap * 2),
_columnBtn([
_dragAndTargetBtn("M2", Colors.redAccent, "miss_2"),
_dragAndTargetBtn("2", Colors.orange, "add_pts_2"),
_dragAndTargetBtn("2", Colors.orange, "sub_pts_2", isX: true),
_dragAndTargetBtn("AST", Colors.blueGrey, "add_ast"),
]),
const SizedBox(width: 15),
_dragAndTargetBtn("M2", Colors.redAccent, "miss_2", baseSize, feedSize, sf),
_dragAndTargetBtn("2", Colors.orange, "add_pts_2", baseSize, feedSize, sf),
_dragAndTargetBtn("2", Colors.orange, "sub_pts_2", baseSize, feedSize, sf, isX: true),
_dragAndTargetBtn("AST", Colors.blueGrey, "add_ast", baseSize, feedSize, sf),
], gap),
SizedBox(width: gap * 2),
_columnBtn([
_dragAndTargetBtn("M3", Colors.redAccent, "miss_3"),
_dragAndTargetBtn("3", Colors.orange, "add_pts_3"),
_dragAndTargetBtn("3", Colors.orange, "sub_pts_3", isX: true),
_dragAndTargetBtn("TOV", Colors.redAccent, "add_tov"),
]),
const SizedBox(width: 15),
_dragAndTargetBtn("M3", Colors.redAccent, "miss_3", baseSize, feedSize, sf),
_dragAndTargetBtn("3", Colors.orange, "add_pts_3", baseSize, feedSize, sf),
_dragAndTargetBtn("3", Colors.orange, "sub_pts_3", baseSize, feedSize, sf, isX: true),
_dragAndTargetBtn("TOV", Colors.redAccent, "add_tov", baseSize, feedSize, sf),
], gap),
SizedBox(width: gap * 2),
_columnBtn([
_actionBtn("T.O", const Color(0xFFD92C2C), () => controller.useTimeout(true), labelSize: 20),
_dragAndTargetBtn("ORB", const Color(0xFF1E2A38), "add_rbs", icon: Icons.sports_basketball),
_dragAndTargetBtn("DRB", const Color(0xFF1E2A38), "add_rbs", icon: Icons.sports_basketball),
_dragAndTargetBtn("BLK", Colors.deepPurple, "add_blk", icon: Icons.front_hand),
]),
const SizedBox(width: 15),
_columnBtn([
])
_actionBtn("T.O", const Color(0xFFD92C2C), () => controller.useTimeout(true), baseSize, feedSize, sf),
_dragAndTargetBtn("ORB", const Color(0xFF1E2A38), "add_rbs", baseSize, feedSize, sf, icon: Icons.sports_basketball),
_dragAndTargetBtn("DRB", const Color(0xFF1E2A38), "add_rbs", baseSize, feedSize, sf, icon: Icons.sports_basketball),
_dragAndTargetBtn("BLK", Colors.deepPurple, "add_blk", baseSize, feedSize, sf, icon: Icons.front_hand),
], gap),
],
);
}
// Mantenha os métodos _columnBtn, _dragAndTargetBtn, _actionBtn e _circle exatamente como estão
Widget _columnBtn(List<Widget> children) => Column(mainAxisSize: MainAxisSize.min, children: children.map((c) => Padding(padding: const EdgeInsets.only(bottom: 8), child: c)).toList());
Widget _columnBtn(List<Widget> children, double gap) => Column(mainAxisSize: MainAxisSize.min, children: children.map((c) => Padding(padding: EdgeInsets.only(bottom: gap), child: c)).toList());
Widget _dragAndTargetBtn(String label, Color color, String actionData, {IconData? icon, bool isX = false}) {
Widget _dragAndTargetBtn(String label, Color color, String actionData, double baseSize, double feedSize, double sf, {IconData? icon, bool isX = false}) {
return Draggable<String>(
data: actionData,
feedback: _circle(label, color, icon, true, isX: isX),
childWhenDragging: Opacity(opacity: 0.5, child: _circle(label, color, icon, false, isX: isX)),
feedback: _circle(label, color, icon, true, baseSize, feedSize, sf, isX: isX),
childWhenDragging: Opacity(opacity: 0.5, child: _circle(label, color, icon, false, baseSize, feedSize, sf, isX: isX)),
child: DragTarget<String>(
onAcceptWithDetails: (details) {
final playerData = details.data;
// Requer um BuildContext, não acessível diretamente no Stateless, então não fazemos nada aqui.
// O target real está no PlayerCourtCard!
},
onAcceptWithDetails: (details) {},
builder: (context, candidateData, rejectedData) {
bool isHovered = candidateData.any((data) => data != null && data.startsWith("player_"));
return Transform.scale(
scale: isHovered ? 1.15 : 1.0,
child: Container(decoration: isHovered ? BoxDecoration(shape: BoxShape.circle, boxShadow: const [BoxShadow(color: Colors.white, blurRadius: 10, spreadRadius: 3)]) : null, child: _circle(label, color, icon, false, isX: isX)),
child: Container(decoration: isHovered ? BoxDecoration(shape: BoxShape.circle, boxShadow: [BoxShadow(color: Colors.white, blurRadius: 10 * sf, spreadRadius: 3 * sf)]) : null, child: _circle(label, color, icon, false, baseSize, feedSize, sf, isX: isX)),
);
}
),
);
}
Widget _actionBtn(String label, Color color, VoidCallback onTap, {IconData? icon, bool isX = false, double labelSize = 24}) {
return GestureDetector(onTap: onTap, child: _circle(label, color, icon, false, fontSize: labelSize, isX: isX));
Widget _actionBtn(String label, Color color, VoidCallback onTap, double baseSize, double feedSize, double sf, {IconData? icon, bool isX = false}) {
return GestureDetector(onTap: onTap, child: _circle(label, color, icon, false, baseSize, feedSize, sf, isX: isX));
}
Widget _circle(String label, Color color, IconData? icon, bool isFeed, {double fontSize = 20, bool isX = false}) {
Widget _circle(String label, Color color, IconData? icon, bool isFeed, double baseSize, double feedSize, double sf, {bool isX = false}) {
double size = isFeed ? feedSize : baseSize;
Widget content;
bool isPointBtn = label == "1" || label == "2" || label == "3" || label == "M2" || label == "M3";
bool isBlkBtn = label == "BLK";
@@ -290,12 +287,12 @@ class ActionButtonsPanel extends StatelessWidget {
content = Stack(
alignment: Alignment.center,
children: [
Container(width: isFeed ? 55 : 45, height: isFeed ? 55 : 45, decoration: const BoxDecoration(color: Colors.black, shape: BoxShape.circle)),
Icon(Icons.sports_basketball, color: color, size: isFeed ? 65 : 55),
Container(width: size * 0.75, height: size * 0.75, decoration: const BoxDecoration(color: Colors.black, shape: BoxShape.circle)),
Icon(Icons.sports_basketball, color: color, size: size * 0.9),
Stack(
children: [
Text(label, style: TextStyle(fontSize: isFeed ? 26 : 22, fontWeight: FontWeight.w900, foreground: Paint()..style = PaintingStyle.stroke..strokeWidth = 3..color = Colors.white, decoration: TextDecoration.none)),
Text(label, style: TextStyle(fontSize: isFeed ? 26 : 22, fontWeight: FontWeight.w900, color: Colors.black, decoration: TextDecoration.none)),
Text(label, style: TextStyle(fontSize: size * 0.38, fontWeight: FontWeight.w900, foreground: Paint()..style = PaintingStyle.stroke..strokeWidth = size * 0.05..color = Colors.white, decoration: TextDecoration.none)),
Text(label, style: TextStyle(fontSize: size * 0.38, fontWeight: FontWeight.w900, color: Colors.black, decoration: TextDecoration.none)),
],
),
],
@@ -305,33 +302,32 @@ class ActionButtonsPanel extends StatelessWidget {
content = Stack(
alignment: Alignment.center,
children: [
Icon(Icons.front_hand, color: const Color.fromARGB(207, 56, 52, 52), size: isFeed ? 55 : 45),
Icon(Icons.front_hand, color: const Color.fromARGB(207, 56, 52, 52), size: size * 0.75),
Stack(
alignment: Alignment.center,
children: [
Text(label, style: TextStyle(fontSize: isFeed ? 18 : 16, fontWeight: FontWeight.w900, foreground: Paint()..style = PaintingStyle.stroke..strokeWidth = 3..color = Colors.black, decoration: TextDecoration.none)),
Text(label, style: TextStyle(fontSize: isFeed ? 18 : 16, fontWeight: FontWeight.w900, color: Colors.white, decoration: TextDecoration.none)),
Text(label, style: TextStyle(fontSize: size * 0.28, fontWeight: FontWeight.w900, foreground: Paint()..style = PaintingStyle.stroke..strokeWidth = size * 0.05..color = Colors.black, decoration: TextDecoration.none)),
Text(label, style: TextStyle(fontSize: size * 0.28, fontWeight: FontWeight.w900, color: Colors.white, decoration: TextDecoration.none)),
],
),
],
);
} else if (icon != null) {
content = Icon(icon, color: Colors.white, size: 30);
content = Icon(icon, color: Colors.white, size: size * 0.5);
} else {
content = Text(label, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: fontSize, decoration: TextDecoration.none));
content = Text(label, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: size * 0.35, decoration: TextDecoration.none));
}
return Stack(
clipBehavior: Clip.none, alignment: Alignment.bottomRight,
children: [
Container(
width: isFeed ? 70 : 60, height: isFeed ? 70 : 60,
decoration: (isPointBtn || isBlkBtn) ? const BoxDecoration(color: Colors.transparent) : BoxDecoration(gradient: RadialGradient(colors: [color.withOpacity(0.7), color], radius: 0.8), shape: BoxShape.circle, boxShadow: const [BoxShadow(color: Colors.black38, blurRadius: 6, offset: Offset(0, 3))]),
width: size, height: size,
decoration: (isPointBtn || isBlkBtn) ? const BoxDecoration(color: Colors.transparent) : BoxDecoration(gradient: RadialGradient(colors: [color.withOpacity(0.7), color], radius: 0.8), shape: BoxShape.circle, boxShadow: [BoxShadow(color: Colors.black38, blurRadius: 6 * sf, offset: Offset(0, 3 * sf))]),
alignment: Alignment.center, child: content,
),
if (isX) Positioned(top: 0, right: 0, child: Container(decoration: const BoxDecoration(color: Colors.white, shape: BoxShape.circle), child: Icon(Icons.cancel, color: Colors.red, size: isFeed ? 28 : 24))),
if (isX) Positioned(top: 0, right: 0, child: Container(decoration: const BoxDecoration(color: Colors.white, shape: BoxShape.circle), child: Icon(Icons.cancel, color: Colors.red, size: size * 0.4))),
],
);
}
}