melhorar o calor
This commit is contained in:
@@ -8,7 +8,6 @@ class ShotRecord {
|
||||
final double relativeY;
|
||||
final bool isMake;
|
||||
final String playerName;
|
||||
// 👇 AGORA ACEITA ZONAS E PONTOS!
|
||||
final String? zone;
|
||||
final int? points;
|
||||
|
||||
@@ -72,7 +71,6 @@ class PlacarController {
|
||||
Timer? timer;
|
||||
bool isRunning = false;
|
||||
|
||||
// 👇 VARIÁVEIS DE CALIBRAÇÃO DO CAMPO (OS TEUS NÚMEROS!) 👇
|
||||
bool isCalibrating = false;
|
||||
double hoopBaseX = 0.088;
|
||||
double arcRadius = 0.459;
|
||||
@@ -90,6 +88,7 @@ class PlacarController {
|
||||
playerStats.clear();
|
||||
playerNumbers.clear();
|
||||
playerDbIds.clear();
|
||||
matchShots.clear(); // Limpa as bolas do último jogo
|
||||
myFouls = 0;
|
||||
opponentFouls = 0;
|
||||
|
||||
@@ -159,6 +158,19 @@ class PlacarController {
|
||||
}
|
||||
_padTeam(oppCourt, oppBench, "Adversário", isMyTeam: false);
|
||||
|
||||
// 👇 CARREGA AS BOLINHAS ANTIGAS (MAPA DE CALOR DO JOGO ATUAL) 👇
|
||||
final shotsResponse = await supabase.from('shot_locations').select().eq('game_id', gameId);
|
||||
for (var shotData in shotsResponse) {
|
||||
matchShots.add(ShotRecord(
|
||||
relativeX: double.parse(shotData['relative_x'].toString()),
|
||||
relativeY: double.parse(shotData['relative_y'].toString()),
|
||||
isMake: shotData['is_make'] == true,
|
||||
playerName: shotData['player_name'].toString(),
|
||||
zone: shotData['zone']?.toString(),
|
||||
points: shotData['points'] != null ? int.parse(shotData['points'].toString()) : null,
|
||||
));
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
onUpdate();
|
||||
} catch (e) {
|
||||
@@ -282,10 +294,7 @@ class PlacarController {
|
||||
// 👇 REGISTA PONTOS VINDO DO POP-UP AMARELO (E MARCA A BOLINHA)
|
||||
// =========================================================================
|
||||
void registerShotFromPopup(BuildContext context, String action, String targetPlayer, String zone, int points, double relativeX, double relativeY) {
|
||||
if (!isRunning) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('⏳ O relógio está parado! Inicie o tempo primeiro.'), backgroundColor: Colors.red));
|
||||
return;
|
||||
}
|
||||
// 💡 AVISO AMIGÁVEL REMOVIDO. Agora podes marcar pontos mesmo com o tempo parado!
|
||||
|
||||
String name = targetPlayer.replaceAll("player_my_", "").replaceAll("player_opp_", "");
|
||||
bool isMyTeam = targetPlayer.startsWith("player_my_");
|
||||
@@ -331,7 +340,6 @@ class PlacarController {
|
||||
onUpdate();
|
||||
}
|
||||
|
||||
|
||||
// MANTIDO PARA CASO USES A MARCAÇÃO CLÁSSICA DIRETAMENTE NO CAMPO ESCURO
|
||||
void registerShotLocation(BuildContext context, Offset position, Size size) {
|
||||
if (pendingAction == null || pendingPlayer == null) return;
|
||||
@@ -537,8 +545,32 @@ class PlacarController {
|
||||
await supabase.from('player_stats').insert(batchStats);
|
||||
}
|
||||
|
||||
// 👇 6. GUARDA AS BOLINHAS (MAPA DE CALOR) NO SUPABASE 👇
|
||||
List<Map<String, dynamic>> batchShots = [];
|
||||
for (var shot in matchShots) {
|
||||
String? memberDbId = playerDbIds[shot.playerName];
|
||||
if (memberDbId != null) {
|
||||
batchShots.add({
|
||||
'game_id': gameId,
|
||||
'member_id': memberDbId,
|
||||
'player_name': shot.playerName,
|
||||
'relative_x': shot.relativeX,
|
||||
'relative_y': shot.relativeY,
|
||||
'is_make': shot.isMake,
|
||||
'zone': shot.zone ?? 'Desconhecida',
|
||||
'points': shot.points ?? (shot.isMake ? 2 : 0),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Apaga os antigos (para não duplicar) e guarda os novos!
|
||||
await supabase.from('shot_locations').delete().eq('game_id', gameId);
|
||||
if (batchShots.isNotEmpty) {
|
||||
await supabase.from('shot_locations').insert(batchShots);
|
||||
}
|
||||
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Estatísticas e Resultados guardados com Sucesso!'), backgroundColor: Colors.green));
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Estatísticas, Mapa de Calor e Resultados guardados com Sucesso!'), backgroundColor: Colors.green));
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
|
||||
@@ -2,11 +2,456 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:playmaker/controllers/placar_controller.dart';
|
||||
import 'package:playmaker/utils/size_extension.dart';
|
||||
import 'package:playmaker/widgets/placar_widgets.dart'; // 👇 As tuas classes extra vivem aqui!
|
||||
import 'package:playmaker/classe/theme.dart'; // 👇 IMPORT DO TEU TEMA!
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:playmaker/zone_map_dialog.dart';
|
||||
|
||||
// ============================================================================
|
||||
// 1. PLACAR SUPERIOR (CRONÓMETRO E RESULTADO)
|
||||
// ============================================================================
|
||||
class TopScoreboard extends StatelessWidget {
|
||||
final PlacarController controller;
|
||||
final double sf;
|
||||
|
||||
const TopScoreboard({super.key, required this.controller, required this.sf});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 10 * sf, horizontal: 35 * sf),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.placarDarkSurface, // 🎨 USANDO TEMA
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(22 * sf),
|
||||
bottomRight: Radius.circular(22 * sf)
|
||||
),
|
||||
border: Border.all(color: Colors.white, width: 2.5 * sf),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildTeamSection(controller.myTeam, controller.myScore, controller.myFouls, controller.myTimeoutsUsed, AppTheme.myTeamBlue, false, sf), // 🎨 USANDO TEMA
|
||||
SizedBox(width: 30 * sf),
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 18 * sf, vertical: 5 * sf),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.placarTimerBg, // 🎨 USANDO TEMA
|
||||
borderRadius: BorderRadius.circular(9 * sf)
|
||||
),
|
||||
child: Text(
|
||||
controller.formatTime(),
|
||||
style: TextStyle(color: Colors.white, fontSize: 28 * sf, fontWeight: FontWeight.w900, fontFamily: 'monospace', letterSpacing: 2 * sf)
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5 * sf),
|
||||
Text(
|
||||
"PERÍODO ${controller.currentQuarter}",
|
||||
style: TextStyle(color: AppTheme.warningAmber, fontSize: 14 * sf, fontWeight: FontWeight.w900)
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(width: 30 * sf),
|
||||
_buildTeamSection(controller.opponentTeam, controller.opponentScore, controller.opponentFouls, controller.opponentTimeoutsUsed, AppTheme.oppTeamRed, true, sf), // 🎨 USANDO TEMA
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTeamSection(String name, int score, int fouls, int timeouts, Color color, bool isOpp, double sf) {
|
||||
int displayFouls = fouls > 5 ? 5 : fouls;
|
||||
|
||||
final timeoutIndicators = Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: List.generate(3, (index) => Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 3.5 * sf),
|
||||
width: 12 * sf, height: 12 * sf,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: index < timeouts ? AppTheme.warningAmber : Colors.grey.shade600,
|
||||
border: Border.all(color: Colors.white54, width: 1.5 * sf)
|
||||
),
|
||||
)),
|
||||
);
|
||||
|
||||
List<Widget> content = [
|
||||
Column(
|
||||
children: [
|
||||
_scoreBox(score, color, sf),
|
||||
SizedBox(height: 7 * sf),
|
||||
timeoutIndicators
|
||||
]
|
||||
),
|
||||
SizedBox(width: 18 * sf),
|
||||
Column(
|
||||
crossAxisAlignment: isOpp ? CrossAxisAlignment.start : CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
name.toUpperCase(),
|
||||
style: TextStyle(color: Colors.white, fontSize: 20 * sf, fontWeight: FontWeight.w900, letterSpacing: 1.2 * sf)
|
||||
),
|
||||
SizedBox(height: 5 * sf),
|
||||
Text(
|
||||
"FALTAS: $displayFouls",
|
||||
style: TextStyle(color: displayFouls >= 5 ? AppTheme.actionMiss : AppTheme.warningAmber, fontSize: 13 * sf, fontWeight: FontWeight.bold)
|
||||
),
|
||||
],
|
||||
)
|
||||
];
|
||||
|
||||
return Row(crossAxisAlignment: CrossAxisAlignment.center, children: isOpp ? content : content.reversed.toList());
|
||||
}
|
||||
|
||||
Widget _scoreBox(int score, Color color, double sf) => Container(
|
||||
width: 58 * sf, height: 45 * sf,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(7 * sf)),
|
||||
child: Text(score.toString(), style: TextStyle(color: Colors.white, fontSize: 26 * sf, fontWeight: FontWeight.w900)),
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 2. BANCO DE SUPLENTES (DRAG & DROP)
|
||||
// ============================================================================
|
||||
class BenchPlayersList extends StatelessWidget {
|
||||
final PlacarController controller;
|
||||
final bool isOpponent;
|
||||
final double sf;
|
||||
|
||||
const BenchPlayersList({super.key, required this.controller, required this.isOpponent, required this.sf});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bench = isOpponent ? controller.oppBench : controller.myBench;
|
||||
final teamColor = isOpponent ? AppTheme.oppTeamRed : AppTheme.myTeamBlue; // 🎨 TEMA
|
||||
final prefix = isOpponent ? "bench_opp_" : "bench_my_";
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: bench.map((playerName) {
|
||||
final num = controller.playerNumbers[playerName] ?? "0";
|
||||
final int fouls = controller.playerStats[playerName]?["fls"] ?? 0;
|
||||
final bool isFouledOut = fouls >= 5;
|
||||
|
||||
Widget avatarUI = Container(
|
||||
margin: EdgeInsets.only(bottom: 7 * sf),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white, width: 1.8 * sf),
|
||||
boxShadow: [BoxShadow(color: Colors.black45, blurRadius: 5 * sf, offset: Offset(0, 2.5 * sf))]
|
||||
),
|
||||
child: CircleAvatar(
|
||||
radius: 22 * sf,
|
||||
backgroundColor: isFouledOut ? Colors.grey.shade800 : teamColor,
|
||||
child: Text(
|
||||
num,
|
||||
style: TextStyle(
|
||||
color: isFouledOut ? Colors.red.shade300 : Colors.white,
|
||||
fontSize: 16 * 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: AppTheme.actionMiss)),
|
||||
child: avatarUI
|
||||
);
|
||||
}
|
||||
|
||||
return Draggable<String>(
|
||||
data: "$prefix$playerName",
|
||||
feedback: Material(
|
||||
color: Colors.transparent,
|
||||
child: CircleAvatar(
|
||||
radius: 28 * sf,
|
||||
backgroundColor: teamColor,
|
||||
child: Text(num, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 18 * sf))
|
||||
)
|
||||
),
|
||||
childWhenDragging: Opacity(opacity: 0.5, child: SizedBox(width: 45 * sf, height: 45 * sf)),
|
||||
child: avatarUI,
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 3. CARTÃO DO JOGADOR NO CAMPO (TARGET DE FALTAS/PONTOS/SUBSTITUIÇÕES)
|
||||
// ============================================================================
|
||||
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, required this.sf});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final teamColor = isOpponent ? AppTheme.oppTeamRed : AppTheme.myTeamBlue; // 🎨 TEMA
|
||||
final stats = controller.playerStats[name]!;
|
||||
final number = controller.playerNumbers[name]!;
|
||||
final prefix = isOpponent ? "player_opp_" : "player_my_";
|
||||
|
||||
return Draggable<String>(
|
||||
data: "$prefix$name",
|
||||
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)),
|
||||
),
|
||||
),
|
||||
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 == "add_pts_2" || action == "add_pts_3" || action == "miss_2" || action == "miss_3") {
|
||||
bool isMake = action.startsWith("add_");
|
||||
bool is3Pt = action.endsWith("_3");
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => ZoneMapDialog(
|
||||
playerName: name,
|
||||
isMake: isMake,
|
||||
is3PointAction: is3Pt,
|
||||
onZoneSelected: (zone, points, relX, relY) {
|
||||
Navigator.pop(ctx);
|
||||
controller.registerShotFromPopup(context, action, "$prefix$name", zone, points, relX, relY);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
else 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, sf);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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 borderColor = isFouledOut ? AppTheme.actionMiss : Colors.transparent;
|
||||
|
||||
if (isSubbing) {
|
||||
bgColor = Colors.blue.shade50; borderColor = AppTheme.myTeamBlue;
|
||||
} else if (isActionHover && !isFouledOut) {
|
||||
bgColor = Colors.orange.shade50; borderColor = AppTheme.actionPoints;
|
||||
}
|
||||
|
||||
int fgm = stats["fgm"]!;
|
||||
int fga = stats["fga"]!;
|
||||
String fgPercent = fga > 0 ? ((fgm / fga) * 100).toStringAsFixed(0) : "0";
|
||||
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))],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(9 * sf),
|
||||
child: IntrinsicHeight(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16 * sf),
|
||||
color: isFouledOut ? Colors.grey[700] : teamColor,
|
||||
alignment: Alignment.center,
|
||||
child: Text(number, style: TextStyle(color: Colors.white, fontSize: 22 * sf, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12 * sf, vertical: 7 * sf),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
displayName,
|
||||
style: TextStyle(fontSize: 16 * sf, fontWeight: FontWeight.bold, color: isFouledOut ? AppTheme.actionMiss : Colors.black87, decoration: isFouledOut ? TextDecoration.lineThrough : TextDecoration.none)
|
||||
),
|
||||
SizedBox(height: 2.5 * sf),
|
||||
Text(
|
||||
"${stats["pts"]} Pts | FG: $fgm/$fga ($fgPercent%)",
|
||||
style: TextStyle(fontSize: 12 * sf, color: isFouledOut ? AppTheme.actionMiss : Colors.grey[700], fontWeight: FontWeight.w600)
|
||||
),
|
||||
Text(
|
||||
"${stats["ast"]} Ast | ${stats["orb"]! + stats["drb"]!} Rbs | ${stats["fls"]} Fls",
|
||||
style: TextStyle(fontSize: 12 * sf, color: isFouledOut ? AppTheme.actionMiss : Colors.grey[500], fontWeight: FontWeight.w600)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 4. PAINEL DE BOTÕES DE AÇÃO (PONTOS, RESSALTOS, ETC)
|
||||
// ============================================================================
|
||||
class ActionButtonsPanel extends StatelessWidget {
|
||||
final PlacarController controller;
|
||||
final double sf;
|
||||
|
||||
const ActionButtonsPanel({super.key, required this.controller, required this.sf});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double baseSize = 65 * sf;
|
||||
final double feedSize = 82 * sf;
|
||||
final double gap = 7 * sf;
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
_columnBtn([
|
||||
_dragAndTargetBtn("M1", AppTheme.actionMiss, "miss_1", baseSize, feedSize, sf), // 🎨 TEMA
|
||||
_dragAndTargetBtn("1", AppTheme.actionPoints, "add_pts_1", baseSize, feedSize, sf), // 🎨 TEMA
|
||||
_dragAndTargetBtn("1", AppTheme.actionPoints, "sub_pts_1", baseSize, feedSize, sf, isX: true),
|
||||
_dragAndTargetBtn("STL", AppTheme.actionSteal, "add_stl", baseSize, feedSize, sf), // 🎨 TEMA
|
||||
], gap),
|
||||
SizedBox(width: gap * 1),
|
||||
_columnBtn([
|
||||
_dragAndTargetBtn("M2", AppTheme.actionMiss, "miss_2", baseSize, feedSize, sf),
|
||||
_dragAndTargetBtn("2", AppTheme.actionPoints, "add_pts_2", baseSize, feedSize, sf),
|
||||
_dragAndTargetBtn("2", AppTheme.actionPoints, "sub_pts_2", baseSize, feedSize, sf, isX: true),
|
||||
_dragAndTargetBtn("AST", AppTheme.actionAssist, "add_ast", baseSize, feedSize, sf), // 🎨 TEMA
|
||||
], gap),
|
||||
SizedBox(width: gap * 1),
|
||||
_columnBtn([
|
||||
_dragAndTargetBtn("M3", AppTheme.actionMiss, "miss_3", baseSize, feedSize, sf),
|
||||
_dragAndTargetBtn("3", AppTheme.actionPoints, "add_pts_3", baseSize, feedSize, sf),
|
||||
_dragAndTargetBtn("3", AppTheme.actionPoints, "sub_pts_3", baseSize, feedSize, sf, isX: true),
|
||||
_dragAndTargetBtn("TOV", AppTheme.actionMiss, "add_tov", baseSize, feedSize, sf),
|
||||
], gap),
|
||||
SizedBox(width: gap * 1),
|
||||
_columnBtn([
|
||||
_dragAndTargetBtn("ORB", AppTheme.actionRebound, "add_orb", baseSize, feedSize, sf, icon: Icons.sports_basketball), // 🎨 TEMA
|
||||
_dragAndTargetBtn("DRB", AppTheme.actionRebound, "add_drb", baseSize, feedSize, sf, icon: Icons.sports_basketball), // 🎨 TEMA
|
||||
_dragAndTargetBtn("BLK", AppTheme.actionBlock, "add_blk", baseSize, feedSize, sf, icon: Icons.front_hand), // 🎨 TEMA
|
||||
], gap),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _columnBtn(List<Widget> children, double gap) {
|
||||
return 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, double baseSize, double feedSize, double sf, {IconData? icon, bool isX = false}) {
|
||||
return Draggable<String>(
|
||||
data: actionData,
|
||||
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) {},
|
||||
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: [BoxShadow(color: Colors.white, blurRadius: 10 * sf, spreadRadius: 3 * sf)]) : null,
|
||||
child: _circle(label, color, icon, false, baseSize, feedSize, sf, isX: isX)
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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 == "M1" || label == "M2" || label == "M3";
|
||||
bool isBlkBtn = label == "BLK";
|
||||
|
||||
if (isPointBtn) {
|
||||
content = Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
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: 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)),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (isBlkBtn) {
|
||||
content = Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
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: 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: size * 0.5);
|
||||
} else {
|
||||
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: 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: size * 0.4))),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PlacarPage extends StatefulWidget {
|
||||
final String gameId, myTeam, opponentTeam;
|
||||
|
||||
@@ -27,7 +472,6 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Obriga o telemóvel a ficar deitado
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.landscapeRight,
|
||||
DeviceOrientation.landscapeLeft,
|
||||
@@ -47,12 +491,10 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
// Volta a deixar o telemóvel ao alto quando sais
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// --- 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,
|
||||
@@ -83,7 +525,6 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
);
|
||||
}
|
||||
|
||||
// --- 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,
|
||||
@@ -100,22 +541,30 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
void _showHeatmap(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => HeatmapDialog(
|
||||
shots: _controller.matchShots,
|
||||
myTeamName: _controller.myTeam,
|
||||
oppTeamName: _controller.opponentTeam,
|
||||
myPlayers: [..._controller.myCourt, ..._controller.myBench],
|
||||
oppPlayers: [..._controller.oppCourt, ..._controller.oppBench],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double wScreen = MediaQuery.of(context).size.width;
|
||||
final double hScreen = MediaQuery.of(context).size.height;
|
||||
|
||||
// 👇 CÁLCULO MANUAL DO SF 👇
|
||||
final double sf = math.min(wScreen / 1150, hScreen / 720);
|
||||
final double cornerBtnSize = 48 * sf; // Tamanho ideal
|
||||
final double cornerBtnSize = 48 * sf;
|
||||
|
||||
// ==========================================
|
||||
// ECRÃ DE CARREGAMENTO (LOADING)
|
||||
// ==========================================
|
||||
if (_controller.isLoading) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFF16202C),
|
||||
backgroundColor: AppTheme.placarDarkSurface, // 🎨 TEMA
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -133,7 +582,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: 26 * sf, fontStyle: FontStyle.italic));
|
||||
return Text(frase, style: TextStyle(color: AppTheme.actionPoints.withOpacity(0.7), fontSize: 26 * sf, fontStyle: FontStyle.italic)); // 🎨 TEMA
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -142,20 +591,16 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
);
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// ECRÃ PRINCIPAL (O JOGO)
|
||||
// ==========================================
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFF266174),
|
||||
backgroundColor: AppTheme.placarBackground, // 🎨 TEMA (Fundo azul bonito)
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
// 👇 IGNORE POINTER BLOQUEIA CLIQUES ENQUANTO GUARDA 👇
|
||||
child: IgnorePointer(
|
||||
ignoring: _controller.isSaving,
|
||||
child: Stack(
|
||||
children: [
|
||||
// --- 1. O CAMPO ---
|
||||
// --- 1. O CAMPO LIMPO ---
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: 65 * sf, right: 65 * sf, bottom: 55 * sf),
|
||||
decoration: BoxDecoration(border: Border.all(color: Colors.white, width: 2.5)),
|
||||
@@ -179,22 +624,9 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
children: _controller.matchShots.map((shot) => Positioned(
|
||||
// Posição calculada matematicamente pelo click anterior
|
||||
left: (shot.relativeX * w) - (9 * context.sf),
|
||||
top: (shot.relativeY * h) - (9 * context.sf),
|
||||
child: CircleAvatar(
|
||||
radius: 9 * context.sf,
|
||||
backgroundColor: shot.isMake ? Colors.green : Colors.red,
|
||||
child: Icon(shot.isMake ? Icons.check : Icons.close, size: 11 * context.sf, color: Colors.white)
|
||||
),
|
||||
)).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// --- 2. JOGADORES NO CAMPO ---
|
||||
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)),
|
||||
@@ -209,13 +641,11 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
Positioned(top: h * 0.80, right: w * 0.20, child: PlayerCourtCard(controller: _controller, name: _controller.oppCourt[4], isOpponent: true, sf: sf)),
|
||||
],
|
||||
|
||||
// --- 3. BOTÕES DE FALTAS NO CAMPO ---
|
||||
if (!_controller.isSelectingShotLocation) ...[
|
||||
_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),
|
||||
_buildFloatingFoulBtn("FALTA +", AppTheme.actionPoints, "add_foul", Icons.sports, w * 0.39, 0.0, h * 0.31, sf), // 🎨 TEMA
|
||||
_buildFloatingFoulBtn("FALTA -", AppTheme.actionMiss, "sub_foul", Icons.block, 0.0, w * 0.39, h * 0.31, sf), // 🎨 TEMA
|
||||
],
|
||||
|
||||
// --- 4. BOTÃO PLAY/PAUSE NO MEIO ---
|
||||
if (!_controller.isSelectingShotLocation)
|
||||
Positioned(
|
||||
top: (h * 0.32) + (40 * sf),
|
||||
@@ -232,13 +662,10 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
),
|
||||
),
|
||||
|
||||
// --- 5. PLACAR LÁ NO TOPO ---
|
||||
Positioned(top: 0, left: 0, right: 0, child: Center(child: TopScoreboard(controller: _controller, sf: sf))),
|
||||
|
||||
// --- 6. PAINEL DE BOTÕES DE AÇÃO LÁ EM BAIXO ---
|
||||
if (!_controller.isSelectingShotLocation) Positioned(bottom: -10 * sf, left: 0, right: 0, child: ActionButtonsPanel(controller: _controller, sf: sf)),
|
||||
|
||||
// --- 7. OVERLAY ESCURO PARA MARCAR PONTO NO CAMPO ---
|
||||
if (_controller.isSelectingShotLocation)
|
||||
Positioned(
|
||||
top: h * 0.4, left: 0, right: 0,
|
||||
@@ -266,11 +693,10 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
child: _buildCornerBtn(
|
||||
heroTag: 'btn_save_exit',
|
||||
icon: Icons.save_alt,
|
||||
color: const Color(0xFFD92C2C),
|
||||
color: AppTheme.oppTeamRed, // 🎨 TEMA
|
||||
size: cornerBtnSize,
|
||||
isLoading: _controller.isSaving,
|
||||
onTap: () async {
|
||||
// Guarda na BD e sai
|
||||
await _controller.saveGameStats(context);
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
@@ -279,6 +705,18 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
),
|
||||
),
|
||||
|
||||
// Topo Direito: Mapa de Calor
|
||||
Positioned(
|
||||
top: 50 * sf, right: 12 * sf,
|
||||
child: _buildCornerBtn(
|
||||
heroTag: 'btn_heatmap',
|
||||
icon: Icons.local_fire_department,
|
||||
color: Colors.orange.shade800,
|
||||
size: cornerBtnSize,
|
||||
onTap: () => _showHeatmap(context),
|
||||
),
|
||||
),
|
||||
|
||||
// Base Esquerda: Banco + TIMEOUT DA CASA
|
||||
Positioned(
|
||||
bottom: 55 * sf, left: 12 * sf,
|
||||
@@ -287,15 +725,15 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
children: [
|
||||
if (_controller.showMyBench) BenchPlayersList(controller: _controller, isOpponent: false, sf: sf),
|
||||
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(); }),
|
||||
_buildCornerBtn(heroTag: 'btn_sub_home', icon: Icons.swap_horiz, color: AppTheme.myTeamBlue, size: cornerBtnSize, onTap: () { _controller.showMyBench = !_controller.showMyBench; _controller.onUpdate(); }), // 🎨 TEMA
|
||||
SizedBox(height: 12 * sf),
|
||||
_buildCornerBtn(
|
||||
heroTag: 'btn_to_home',
|
||||
icon: Icons.timer,
|
||||
color: _controller.myTimeoutsUsed >= 3 ? Colors.grey : const Color(0xFF1E5BB2),
|
||||
color: _controller.myTimeoutsUsed >= 3 ? Colors.grey : AppTheme.myTeamBlue, // 🎨 TEMA
|
||||
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))
|
||||
? () => ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: const Text('🛑 A equipa da casa já usou os 3 Timeouts deste período!'), backgroundColor: AppTheme.actionMiss)) // 🎨 TEMA
|
||||
: () => _controller.useTimeout(false)
|
||||
),
|
||||
],
|
||||
@@ -310,22 +748,21 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
children: [
|
||||
if (_controller.showOppBench) BenchPlayersList(controller: _controller, isOpponent: true, sf: sf),
|
||||
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(); }),
|
||||
_buildCornerBtn(heroTag: 'btn_sub_away', icon: Icons.swap_horiz, color: AppTheme.oppTeamRed, size: cornerBtnSize, onTap: () { _controller.showOppBench = !_controller.showOppBench; _controller.onUpdate(); }), // 🎨 TEMA
|
||||
SizedBox(height: 12 * sf),
|
||||
_buildCornerBtn(
|
||||
heroTag: 'btn_to_away',
|
||||
icon: Icons.timer,
|
||||
color: _controller.opponentTimeoutsUsed >= 3 ? Colors.grey : const Color(0xFFD92C2C),
|
||||
color: _controller.opponentTimeoutsUsed >= 3 ? Colors.grey : AppTheme.oppTeamRed, // 🎨 TEMA
|
||||
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))
|
||||
? () => ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: const Text('🛑 A equipa visitante já usou os 3 Timeouts deste período!'), backgroundColor: AppTheme.actionMiss)) // 🎨 TEMA
|
||||
: () => _controller.useTimeout(true)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 👇 EFEITO VISUAL (Ecrã escurece para mostrar que está a carregar quando se clica no Guardar) 👇
|
||||
if (_controller.isSaving)
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
@@ -338,25 +775,248 @@ class _PlacarPageState extends State<PlacarPage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
void _openZoneMap(String action, String playerData) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => ZoneMapDialog(
|
||||
playerName: playerData.replaceAll("player_my_", "").replaceAll("player_opp_", ""),
|
||||
isMake: action.startsWith("add_"),
|
||||
onZoneSelected: (zone, points, relX, relY) {
|
||||
_controller.registerShotFromPopup(
|
||||
context,
|
||||
action,
|
||||
playerData,
|
||||
zone,
|
||||
points,
|
||||
relX,
|
||||
relY
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 👇 O TEU NOVO MAPA DE CALOR AVANÇADO (FILTRO POR EQUIPA E JOGADOR) 👇
|
||||
// ============================================================================
|
||||
class HeatmapDialog extends StatefulWidget {
|
||||
final List<ShotRecord> shots;
|
||||
final String myTeamName;
|
||||
final String oppTeamName;
|
||||
final List<String> myPlayers;
|
||||
final List<String> oppPlayers;
|
||||
|
||||
const HeatmapDialog({
|
||||
super.key,
|
||||
required this.shots,
|
||||
required this.myTeamName,
|
||||
required this.oppTeamName,
|
||||
required this.myPlayers,
|
||||
required this.oppPlayers,
|
||||
});
|
||||
|
||||
@override
|
||||
State<HeatmapDialog> createState() => _HeatmapDialogState();
|
||||
}
|
||||
|
||||
class _HeatmapDialogState extends State<HeatmapDialog> {
|
||||
String _selectedTeam = 'Ambas as Equipas';
|
||||
String _selectedPlayer = 'Todos os Jogadores';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Color headerColor = const Color(0xFFE88F15);
|
||||
final Color yellowBackground = const Color(0xFFDFAB00);
|
||||
|
||||
final double screenHeight = MediaQuery.of(context).size.height;
|
||||
final double dialogHeight = screenHeight * 0.95;
|
||||
final double dialogWidth = dialogHeight * 1.0;
|
||||
|
||||
// 1. DEFINIR QUAIS BOLINHAS APARECEM CONFORME OS FILTROS
|
||||
List<ShotRecord> filteredShots = widget.shots.where((shot) {
|
||||
// Filtro de Equipa
|
||||
if (_selectedTeam == widget.myTeamName && !widget.myPlayers.contains(shot.playerName)) return false;
|
||||
if (_selectedTeam == widget.oppTeamName && !widget.oppPlayers.contains(shot.playerName)) return false;
|
||||
|
||||
// Filtro de Jogador
|
||||
if (_selectedPlayer != 'Todos os Jogadores' && shot.playerName != _selectedPlayer) return false;
|
||||
|
||||
return true;
|
||||
}).toList();
|
||||
|
||||
// 2. DEFINIR AS OPÇÕES DOS DROPDOWNS
|
||||
List<String> teamOptions = ['Ambas as Equipas', widget.myTeamName, widget.oppTeamName];
|
||||
|
||||
List<String> playerOptions = ['Todos os Jogadores'];
|
||||
Set<String> activePlayers = widget.shots.map((s) => s.playerName).toSet();
|
||||
|
||||
if (_selectedTeam == 'Ambas as Equipas') {
|
||||
playerOptions.addAll(activePlayers);
|
||||
} else if (_selectedTeam == widget.myTeamName) {
|
||||
playerOptions.addAll(activePlayers.where((p) => widget.myPlayers.contains(p)));
|
||||
} else if (_selectedTeam == widget.oppTeamName) {
|
||||
playerOptions.addAll(activePlayers.where((p) => widget.oppPlayers.contains(p)));
|
||||
}
|
||||
|
||||
// Se a equipa mudar e o jogador antigo não pertencer à equipa nova, reseta para "Todos"
|
||||
if (!playerOptions.contains(_selectedPlayer)) {
|
||||
_selectedPlayer = 'Todos os Jogadores';
|
||||
}
|
||||
|
||||
return Dialog(
|
||||
backgroundColor: yellowBackground,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
insetPadding: const EdgeInsets.all(10),
|
||||
child: SizedBox(
|
||||
height: dialogHeight,
|
||||
width: dialogWidth,
|
||||
child: Column(
|
||||
children: [
|
||||
// CABEÇALHO COM OS DOIS FILTROS
|
||||
Container(
|
||||
height: 50, // Aumentei um pouco para caber bem os dropdowns
|
||||
color: headerColor,
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
const Text(
|
||||
"📊 Mapa de Calor",
|
||||
style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const Spacer(),
|
||||
|
||||
// 👇 FILTRO DE EQUIPA 👇
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(color: Colors.black12, borderRadius: BorderRadius.circular(6)),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
value: _selectedTeam,
|
||||
dropdownColor: headerColor,
|
||||
icon: const Icon(Icons.arrow_drop_down, color: Colors.white),
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 13),
|
||||
items: teamOptions.map((String team) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: team,
|
||||
child: Text(team),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? newValue) {
|
||||
setState(() {
|
||||
_selectedTeam = newValue!;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(width: 10),
|
||||
|
||||
// 👇 FILTRO DE JOGADOR 👇
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(color: Colors.black12, borderRadius: BorderRadius.circular(6)),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
value: _selectedPlayer,
|
||||
dropdownColor: headerColor,
|
||||
icon: const Icon(Icons.arrow_drop_down, color: Colors.white),
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 13),
|
||||
items: playerOptions.map((String player) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: player,
|
||||
child: Text(player),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? newValue) {
|
||||
setState(() {
|
||||
_selectedPlayer = newValue!;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(width: 15),
|
||||
|
||||
InkWell(
|
||||
onTap: () => Navigator.pop(context),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: const BoxDecoration(color: Colors.white, shape: BoxShape.circle),
|
||||
child: Icon(Icons.close, color: headerColor, size: 18),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// O CAMPO DESENHADO
|
||||
Expanded(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return Stack(
|
||||
children: [
|
||||
// O Desenho das Linhas do Campo (Usamos um pintor simples)
|
||||
CustomPaint(
|
||||
size: Size(constraints.maxWidth, constraints.maxHeight),
|
||||
painter: HeatmapCourtPainter(),
|
||||
),
|
||||
|
||||
// As Bolinhas por cima do desenho
|
||||
...filteredShots.map((shot) => Positioned(
|
||||
left: (shot.relativeX * constraints.maxWidth) - 8,
|
||||
top: (shot.relativeY * constraints.maxHeight) - 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)
|
||||
),
|
||||
)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Pintor dedicado apenas a desenhar as linhas (sem lógica de sombras do ZoneMap)
|
||||
class HeatmapCourtPainter extends CustomPainter {
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final double w = size.width;
|
||||
final double h = size.height;
|
||||
final double basketX = w / 2;
|
||||
|
||||
final Paint whiteStroke = Paint()..color = Colors.white..style = PaintingStyle.stroke..strokeWidth = 2.0;
|
||||
final Paint blackStroke = Paint()..color = Colors.black87..style = PaintingStyle.stroke..strokeWidth = 2.0;
|
||||
|
||||
final double margin = w * 0.10;
|
||||
final double length = h * 0.35;
|
||||
final double larguraDoArco = (w / 2) - margin;
|
||||
final double alturaDoArco = larguraDoArco * 0.30;
|
||||
final double totalArcoHeight = alturaDoArco * 4;
|
||||
|
||||
canvas.drawLine(Offset(margin, 0), Offset(margin, length), whiteStroke);
|
||||
canvas.drawLine(Offset(w - margin, 0), Offset(w - margin, length), whiteStroke);
|
||||
canvas.drawLine(Offset(0, length), Offset(margin, length), whiteStroke);
|
||||
canvas.drawLine(Offset(w - margin, length), Offset(w, length), whiteStroke);
|
||||
canvas.drawArc(Rect.fromCenter(center: Offset(basketX, length), width: larguraDoArco * 2, height: totalArcoHeight), 0, math.pi, false, whiteStroke);
|
||||
|
||||
double sXL = basketX + (larguraDoArco * math.cos(math.pi * 0.75));
|
||||
double sYL = length + ((totalArcoHeight / 2) * math.sin(math.pi * 0.75));
|
||||
double sXR = basketX + (larguraDoArco * math.cos(math.pi * 0.25));
|
||||
double sYR = length + ((totalArcoHeight / 2) * math.sin(math.pi * 0.25));
|
||||
|
||||
canvas.drawLine(Offset(sXL, sYL), Offset(0, h * 0.85), whiteStroke);
|
||||
canvas.drawLine(Offset(sXR, sYR), Offset(w, h * 0.85), whiteStroke);
|
||||
|
||||
final double pW = w * 0.28;
|
||||
final double pH = h * 0.38;
|
||||
canvas.drawRect(Rect.fromLTWH(basketX - pW / 2, 0, pW, pH), blackStroke);
|
||||
|
||||
final double ftR = pW / 2;
|
||||
canvas.drawArc(Rect.fromCircle(center: Offset(basketX, pH), radius: ftR), 0, math.pi, false, blackStroke);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
canvas.drawArc(Rect.fromCircle(center: Offset(basketX, pH), radius: ftR), math.pi + (i * 2 * (math.pi / 20)), math.pi / 20, false, blackStroke);
|
||||
}
|
||||
|
||||
canvas.drawLine(Offset(basketX - pW / 2, pH), Offset(sXL, sYL), blackStroke);
|
||||
canvas.drawLine(Offset(basketX + pW / 2, pH), Offset(sXR, sYR), blackStroke);
|
||||
|
||||
canvas.drawArc(Rect.fromCircle(center: Offset(basketX, h), radius: w * 0.12), math.pi, math.pi, false, blackStroke);
|
||||
canvas.drawCircle(Offset(basketX, h * 0.12), w * 0.02, blackStroke);
|
||||
canvas.drawLine(Offset(basketX - w * 0.08, h * 0.12 - 5), Offset(basketX + w * 0.08, h * 0.12 - 5), blackStroke);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:playmaker/controllers/placar_controller.dart';
|
||||
import 'package:playmaker/utils/size_extension.dart';
|
||||
import 'package:playmaker/classe/theme.dart';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:playmaker/zone_map_dialog.dart';
|
||||
|
||||
// ============================================================================
|
||||
@@ -16,7 +21,7 @@ class TopScoreboard extends StatelessWidget {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 10 * sf, horizontal: 35 * sf),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF16202C),
|
||||
color: AppTheme.placarDarkSurface,
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(22 * sf),
|
||||
bottomRight: Radius.circular(22 * sf)
|
||||
@@ -26,7 +31,7 @@ class TopScoreboard extends StatelessWidget {
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildTeamSection(controller.myTeam, controller.myScore, controller.myFouls, controller.myTimeoutsUsed, const Color(0xFF1E5BB2), false, sf),
|
||||
_buildTeamSection(controller.myTeam, controller.myScore, controller.myFouls, controller.myTimeoutsUsed, AppTheme.myTeamBlue, false, sf),
|
||||
SizedBox(width: 30 * sf),
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -34,7 +39,7 @@ class TopScoreboard extends StatelessWidget {
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 18 * sf, vertical: 5 * sf),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF2C3E50),
|
||||
color: AppTheme.placarTimerBg,
|
||||
borderRadius: BorderRadius.circular(9 * sf)
|
||||
),
|
||||
child: Text(
|
||||
@@ -45,12 +50,12 @@ class TopScoreboard extends StatelessWidget {
|
||||
SizedBox(height: 5 * sf),
|
||||
Text(
|
||||
"PERÍODO ${controller.currentQuarter}",
|
||||
style: TextStyle(color: Colors.orangeAccent, fontSize: 14 * sf, fontWeight: FontWeight.w900)
|
||||
style: TextStyle(color: AppTheme.warningAmber, fontSize: 14 * sf, fontWeight: FontWeight.w900)
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(width: 30 * sf),
|
||||
_buildTeamSection(controller.opponentTeam, controller.opponentScore, controller.opponentFouls, controller.opponentTimeoutsUsed, const Color(0xFFD92C2C), true, sf),
|
||||
_buildTeamSection(controller.opponentTeam, controller.opponentScore, controller.opponentFouls, controller.opponentTimeoutsUsed, AppTheme.oppTeamRed, true, sf),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -66,7 +71,7 @@ class TopScoreboard extends StatelessWidget {
|
||||
width: 12 * sf, height: 12 * sf,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: index < timeouts ? Colors.yellow : Colors.grey.shade600,
|
||||
color: index < timeouts ? AppTheme.warningAmber : Colors.grey.shade600,
|
||||
border: Border.all(color: Colors.white54, width: 1.5 * sf)
|
||||
),
|
||||
)),
|
||||
@@ -91,7 +96,7 @@ class TopScoreboard extends StatelessWidget {
|
||||
SizedBox(height: 5 * sf),
|
||||
Text(
|
||||
"FALTAS: $displayFouls",
|
||||
style: TextStyle(color: displayFouls >= 5 ? Colors.redAccent : Colors.yellowAccent, fontSize: 13 * sf, fontWeight: FontWeight.bold)
|
||||
style: TextStyle(color: displayFouls >= 5 ? AppTheme.actionMiss : AppTheme.warningAmber, fontSize: 13 * sf, fontWeight: FontWeight.bold)
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -121,7 +126,7 @@ class BenchPlayersList extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bench = isOpponent ? controller.oppBench : controller.myBench;
|
||||
final teamColor = isOpponent ? const Color(0xFFD92C2C) : const Color(0xFF1E5BB2);
|
||||
final teamColor = isOpponent ? AppTheme.oppTeamRed : AppTheme.myTeamBlue;
|
||||
final prefix = isOpponent ? "bench_opp_" : "bench_my_";
|
||||
|
||||
return Column(
|
||||
@@ -155,7 +160,7 @@ class BenchPlayersList extends StatelessWidget {
|
||||
|
||||
if (isFouledOut) {
|
||||
return GestureDetector(
|
||||
onTap: () => ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('🛑 $playerName não pode voltar (Expulso).'), backgroundColor: Colors.red)),
|
||||
onTap: () => ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('🛑 $playerName não pode voltar (Expulso).'), backgroundColor: AppTheme.actionMiss)),
|
||||
child: avatarUI
|
||||
);
|
||||
}
|
||||
@@ -181,9 +186,6 @@ class BenchPlayersList extends StatelessWidget {
|
||||
// ============================================================================
|
||||
// 3. CARTÃO DO JOGADOR NO CAMPO (TARGET DE FALTAS/PONTOS/SUBSTITUIÇÕES)
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// 3. CARTÃO DO JOGADOR NO CAMPO (AGORA ABRE O POPUP AMARELO)
|
||||
// ============================================================================
|
||||
class PlayerCourtCard extends StatelessWidget {
|
||||
final PlacarController controller;
|
||||
final String name;
|
||||
@@ -194,7 +196,7 @@ class PlayerCourtCard extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final teamColor = isOpponent ? const Color(0xFFD92C2C) : const Color(0xFF1E5BB2);
|
||||
final teamColor = isOpponent ? AppTheme.oppTeamRed : AppTheme.myTeamBlue;
|
||||
final stats = controller.playerStats[name]!;
|
||||
final number = controller.playerNumbers[name]!;
|
||||
final prefix = isOpponent ? "player_opp_" : "player_my_";
|
||||
@@ -204,9 +206,9 @@ class PlayerCourtCard extends StatelessWidget {
|
||||
feedback: Material(
|
||||
color: Colors.transparent,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 18 * sf, vertical: 11 * sf),
|
||||
decoration: BoxDecoration(color: teamColor.withOpacity(0.9), borderRadius: BorderRadius.circular(9 * sf)),
|
||||
child: Text(name, style: TextStyle(color: Colors.white, fontSize: 20 * sf, fontWeight: FontWeight.bold)),
|
||||
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)),
|
||||
),
|
||||
),
|
||||
childWhenDragging: Opacity(opacity: 0.5, child: _playerCardUI(number, name, stats, teamColor, false, false, sf)),
|
||||
@@ -214,28 +216,26 @@ class PlayerCourtCard extends StatelessWidget {
|
||||
onAcceptWithDetails: (details) {
|
||||
final action = details.data;
|
||||
|
||||
// 👇 SE FOR UM LANÇAMENTO DE CAMPO (2 OU 3 PONTOS), ABRE O POPUP AMARELO!
|
||||
if (action == "add_pts_2" || action == "add_pts_3" || action == "miss_2" || action == "miss_3") {
|
||||
bool isMake = action.startsWith("add_");
|
||||
bool is3Pt = action.endsWith("_3");
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => ZoneMapDialog(
|
||||
playerName: name,
|
||||
isMake: isMake,
|
||||
is3PointAction: is3Pt,
|
||||
onZoneSelected: (zone, points, relX, relY) {
|
||||
Navigator.pop(ctx); // Fecha o popup amarelo
|
||||
|
||||
// 👇 MANDA OS DADOS PARA O CONTROLLER! (Vais ter de criar esta função no PlacarController)
|
||||
controller.registerShotFromPopup(context, action, "$prefix$name", zone, points, relX, relY);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
// Se for 1 Ponto (Lance Livre), Falta, Ressalto ou Roubo, FAZ TUDO NORMAL!
|
||||
else if (action.startsWith("add_") || action.startsWith("sub_") || action.startsWith("miss_")) {
|
||||
controller.handleActionDrag(context, action, "$prefix$name");
|
||||
} else if (action.startsWith("bench_")) {
|
||||
}
|
||||
else if (action.startsWith("bench_")) {
|
||||
controller.handleSubbing(context, action, name, isOpponent);
|
||||
}
|
||||
},
|
||||
@@ -249,13 +249,15 @@ class PlayerCourtCard extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _playerCardUI(String number, String name, Map<String, int> stats, Color teamColor, bool isSubbing, bool isActionHover, double sf) {
|
||||
// ... (Mantém o teu código de design _playerCardUI que já tinhas aqui dentro, fica igualzinho!)
|
||||
bool isFouledOut = stats["fls"]! >= 5;
|
||||
Color bgColor = isFouledOut ? Colors.red.shade50 : Colors.white;
|
||||
Color borderColor = isFouledOut ? Colors.redAccent : Colors.transparent;
|
||||
Color bgColor = isFouledOut ? Colors.red.shade100 : Colors.white;
|
||||
Color borderColor = isFouledOut ? AppTheme.actionMiss : Colors.transparent;
|
||||
|
||||
if (isSubbing) { bgColor = Colors.blue.shade50; borderColor = Colors.blue; }
|
||||
else if (isActionHover && !isFouledOut) { bgColor = Colors.orange.shade50; borderColor = Colors.orange; }
|
||||
if (isSubbing) {
|
||||
bgColor = Colors.blue.shade50; borderColor = AppTheme.myTeamBlue;
|
||||
} else if (isActionHover && !isFouledOut) {
|
||||
bgColor = Colors.orange.shade50; borderColor = AppTheme.actionPoints;
|
||||
}
|
||||
|
||||
int fgm = stats["fgm"]!;
|
||||
int fga = stats["fga"]!;
|
||||
@@ -263,11 +265,10 @@ 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(11 * sf),
|
||||
border: Border.all(color: borderColor, width: 1.8 * sf),
|
||||
boxShadow: [BoxShadow(color: Colors.black26, blurRadius: 5 * sf, offset: Offset(2 * sf, 3.5 * sf))],
|
||||
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))],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(9 * sf),
|
||||
@@ -288,10 +289,19 @@ class PlayerCourtCard extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(displayName, style: TextStyle(fontSize: 16 * sf, fontWeight: FontWeight.bold, color: isFouledOut ? Colors.red : Colors.black87, decoration: isFouledOut ? TextDecoration.lineThrough : TextDecoration.none)),
|
||||
Text(
|
||||
displayName,
|
||||
style: TextStyle(fontSize: 16 * sf, fontWeight: FontWeight.bold, color: isFouledOut ? AppTheme.actionMiss : Colors.black87, decoration: isFouledOut ? TextDecoration.lineThrough : TextDecoration.none)
|
||||
),
|
||||
SizedBox(height: 2.5 * sf),
|
||||
Text("${stats["pts"]} Pts | FG: $fgm/$fga ($fgPercent%)", style: TextStyle(fontSize: 12 * sf, color: isFouledOut ? Colors.red : Colors.grey[700], fontWeight: FontWeight.w600)),
|
||||
Text("${stats["ast"]} Ast | ${stats["orb"]! + stats["drb"]!} Rbs | ${stats["fls"]} Fls", style: TextStyle(fontSize: 12 * sf, color: isFouledOut ? Colors.red : Colors.grey[500], fontWeight: FontWeight.w600)),
|
||||
Text(
|
||||
"${stats["pts"]} Pts | FG: $fgm/$fga ($fgPercent%)",
|
||||
style: TextStyle(fontSize: 12 * sf, color: isFouledOut ? AppTheme.actionMiss : Colors.grey[700], fontWeight: FontWeight.w600)
|
||||
),
|
||||
Text(
|
||||
"${stats["ast"]} Ast | ${stats["orb"]! + stats["drb"]!} Rbs | ${stats["fls"]} Fls",
|
||||
style: TextStyle(fontSize: 12 * sf, color: isFouledOut ? AppTheme.actionMiss : Colors.grey[500], fontWeight: FontWeight.w600)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -323,30 +333,30 @@ class ActionButtonsPanel extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
_columnBtn([
|
||||
_dragAndTargetBtn("M1", Colors.redAccent, "miss_1", 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),
|
||||
_dragAndTargetBtn("M1", AppTheme.actionMiss, "miss_1", baseSize, feedSize, sf),
|
||||
_dragAndTargetBtn("1", AppTheme.actionPoints, "add_pts_1", baseSize, feedSize, sf),
|
||||
_dragAndTargetBtn("1", AppTheme.actionPoints, "sub_pts_1", baseSize, feedSize, sf, isX: true),
|
||||
_dragAndTargetBtn("STL", AppTheme.actionSteal, "add_stl", baseSize, feedSize, sf),
|
||||
], gap),
|
||||
SizedBox(width: gap * 1),
|
||||
_columnBtn([
|
||||
_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),
|
||||
_dragAndTargetBtn("M2", AppTheme.actionMiss, "miss_2", baseSize, feedSize, sf),
|
||||
_dragAndTargetBtn("2", AppTheme.actionPoints, "add_pts_2", baseSize, feedSize, sf),
|
||||
_dragAndTargetBtn("2", AppTheme.actionPoints, "sub_pts_2", baseSize, feedSize, sf, isX: true),
|
||||
_dragAndTargetBtn("AST", AppTheme.actionAssist, "add_ast", baseSize, feedSize, sf),
|
||||
], gap),
|
||||
SizedBox(width: gap * 1),
|
||||
_columnBtn([
|
||||
_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),
|
||||
_dragAndTargetBtn("M3", AppTheme.actionMiss, "miss_3", baseSize, feedSize, sf),
|
||||
_dragAndTargetBtn("3", AppTheme.actionPoints, "add_pts_3", baseSize, feedSize, sf),
|
||||
_dragAndTargetBtn("3", AppTheme.actionPoints, "sub_pts_3", baseSize, feedSize, sf, isX: true),
|
||||
_dragAndTargetBtn("TOV", AppTheme.actionMiss, "add_tov", baseSize, feedSize, sf),
|
||||
], gap),
|
||||
SizedBox(width: gap * 1),
|
||||
_columnBtn([
|
||||
_dragAndTargetBtn("ORB", const Color(0xFF1E2A38), "add_orb", baseSize, feedSize, sf, icon: Icons.sports_basketball),
|
||||
_dragAndTargetBtn("DRB", const Color(0xFF1E2A38), "add_drb", baseSize, feedSize, sf, icon: Icons.sports_basketball),
|
||||
_dragAndTargetBtn("BLK", Colors.deepPurple, "add_blk", baseSize, feedSize, sf, icon: Icons.front_hand),
|
||||
_dragAndTargetBtn("ORB", AppTheme.actionRebound, "add_orb", baseSize, feedSize, sf, icon: Icons.sports_basketball),
|
||||
_dragAndTargetBtn("DRB", AppTheme.actionRebound, "add_drb", baseSize, feedSize, sf, icon: Icons.sports_basketball),
|
||||
_dragAndTargetBtn("BLK", AppTheme.actionBlock, "add_blk", baseSize, feedSize, sf, icon: Icons.front_hand),
|
||||
], gap),
|
||||
],
|
||||
);
|
||||
@@ -368,7 +378,7 @@ class ActionButtonsPanel extends StatelessWidget {
|
||||
child: _circle(label, color, icon, false, baseSize, feedSize, sf, isX: isX)
|
||||
),
|
||||
child: DragTarget<String>(
|
||||
onAcceptWithDetails: (details) {}, // O PlayerCourtCard é que processa a ação!
|
||||
onAcceptWithDetails: (details) {},
|
||||
builder: (context, candidateData, rejectedData) {
|
||||
bool isHovered = candidateData.any((data) => data != null && data.startsWith("player_"));
|
||||
return Transform.scale(
|
||||
@@ -439,5 +449,648 @@ class ActionButtonsPanel extends StatelessWidget {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 5. PÁGINA DO PLACAR
|
||||
// ============================================================================
|
||||
class PlacarPage extends StatefulWidget {
|
||||
final String gameId, myTeam, opponentTeam;
|
||||
|
||||
const PlacarPage({
|
||||
super.key,
|
||||
required this.gameId,
|
||||
required this.myTeam,
|
||||
required this.opponentTeam
|
||||
});
|
||||
|
||||
@override
|
||||
State<PlacarPage> createState() => _PlacarPageState();
|
||||
}
|
||||
|
||||
class _PlacarPageState extends State<PlacarPage> {
|
||||
late PlacarController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.landscapeRight,
|
||||
DeviceOrientation.landscapeLeft,
|
||||
]);
|
||||
|
||||
_controller = PlacarController(
|
||||
gameId: widget.gameId,
|
||||
myTeam: widget.myTeam,
|
||||
opponentTeam: widget.opponentTeam,
|
||||
onUpdate: () {
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
);
|
||||
_controller.loadPlayers();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
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,
|
||||
right: right > 0 ? right : null,
|
||||
child: Draggable<String>(
|
||||
data: action,
|
||||
feedback: Material(
|
||||
color: Colors.transparent,
|
||||
child: CircleAvatar(
|
||||
radius: 30 * sf,
|
||||
backgroundColor: color.withOpacity(0.8),
|
||||
child: Icon(icon, color: Colors.white, size: 30 * sf)
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 27 * sf,
|
||||
backgroundColor: color,
|
||||
child: Icon(icon, color: Colors.white, size: 28 * sf),
|
||||
),
|
||||
SizedBox(height: 5 * sf),
|
||||
Text(label, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 12 * sf)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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(14 * (size / 50))),
|
||||
elevation: 5,
|
||||
onPressed: isLoading ? null : onTap,
|
||||
child: isLoading
|
||||
? SizedBox(width: size * 0.45, height: size * 0.45, child: const CircularProgressIndicator(color: Colors.white, strokeWidth: 2.5))
|
||||
: Icon(icon, color: Colors.white, size: size * 0.55),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 👇 ATIVA O NOVO MAPA DE CALOR 👇
|
||||
void _showHeatmap(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => HeatmapDialog(
|
||||
shots: _controller.matchShots,
|
||||
myTeamName: _controller.myTeam,
|
||||
oppTeamName: _controller.opponentTeam,
|
||||
myPlayers: [..._controller.myCourt, ..._controller.myBench],
|
||||
oppPlayers: [..._controller.oppCourt, ..._controller.oppBench],
|
||||
playerStats: _controller.playerStats, // Passa os stats para mostrar os pontos
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@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 / 1150, hScreen / 720);
|
||||
final double cornerBtnSize = 48 * sf;
|
||||
|
||||
if (_controller.isLoading) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.placarDarkSurface,
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
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) {
|
||||
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: AppTheme.actionPoints.withOpacity(0.7), fontSize: 26 * sf, fontStyle: FontStyle.italic));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.placarBackground,
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: IgnorePointer(
|
||||
ignoring: _controller.isSaving,
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
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;
|
||||
final h = constraints.maxHeight;
|
||||
|
||||
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.fill,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
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)),
|
||||
],
|
||||
|
||||
if (!_controller.isSelectingShotLocation) ...[
|
||||
_buildFloatingFoulBtn("FALTA +", AppTheme.actionPoints, "add_foul", Icons.sports, w * 0.39, 0.0, h * 0.31, sf),
|
||||
_buildFloatingFoulBtn("FALTA -", AppTheme.actionMiss, "sub_foul", Icons.block, 0.0, w * 0.39, h * 0.31, 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)
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Positioned(top: 0, left: 0, right: 0, child: Center(child: TopScoreboard(controller: _controller, sf: sf))),
|
||||
|
||||
if (!_controller.isSelectingShotLocation) Positioned(bottom: -10 * sf, left: 0, right: 0, child: ActionButtonsPanel(controller: _controller, sf: sf)),
|
||||
|
||||
if (_controller.isSelectingShotLocation)
|
||||
Positioned(
|
||||
top: h * 0.4, left: 0, right: 0,
|
||||
child: Center(
|
||||
child: Container(
|
||||
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)),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
Positioned(
|
||||
top: 50 * sf, left: 12 * sf,
|
||||
child: _buildCornerBtn(
|
||||
heroTag: 'btn_save_exit',
|
||||
icon: Icons.save_alt,
|
||||
color: AppTheme.oppTeamRed,
|
||||
size: cornerBtnSize,
|
||||
isLoading: _controller.isSaving,
|
||||
onTap: () async {
|
||||
await _controller.saveGameStats(context);
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
),
|
||||
),
|
||||
|
||||
Positioned(
|
||||
top: 50 * sf, right: 12 * sf,
|
||||
child: _buildCornerBtn(
|
||||
heroTag: 'btn_heatmap',
|
||||
icon: Icons.local_fire_department,
|
||||
color: Colors.orange.shade800,
|
||||
size: cornerBtnSize,
|
||||
onTap: () => _showHeatmap(context),
|
||||
),
|
||||
),
|
||||
|
||||
Positioned(
|
||||
bottom: 55 * sf, left: 12 * sf,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (_controller.showMyBench) BenchPlayersList(controller: _controller, isOpponent: false, sf: sf),
|
||||
SizedBox(height: 12 * sf),
|
||||
_buildCornerBtn(heroTag: 'btn_sub_home', icon: Icons.swap_horiz, color: AppTheme.myTeamBlue, 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 : AppTheme.myTeamBlue,
|
||||
size: cornerBtnSize,
|
||||
onTap: _controller.myTimeoutsUsed >= 3
|
||||
? () => ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: const Text('🛑 A equipa da casa já usou os 3 Timeouts deste período!'), backgroundColor: AppTheme.actionMiss))
|
||||
: () => _controller.useTimeout(false)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Positioned(
|
||||
bottom: 55 * sf, right: 12 * sf,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (_controller.showOppBench) BenchPlayersList(controller: _controller, isOpponent: true, sf: sf),
|
||||
SizedBox(height: 12 * sf),
|
||||
_buildCornerBtn(heroTag: 'btn_sub_away', icon: Icons.swap_horiz, color: AppTheme.oppTeamRed, 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 : AppTheme.oppTeamRed,
|
||||
size: cornerBtnSize,
|
||||
onTap: _controller.opponentTimeoutsUsed >= 3
|
||||
? () => ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: const Text('🛑 A equipa visitante já usou os 3 Timeouts deste período!'), backgroundColor: AppTheme.actionMiss))
|
||||
: () => _controller.useTimeout(true)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
if (_controller.isSaving)
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
color: Colors.black.withOpacity(0.4),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 👇 O TEU MAPA DE CALOR: ADVERSÁRIO À ESQUERDA | TUA EQUIPA À DIREITA 👇
|
||||
// ============================================================================
|
||||
class HeatmapDialog extends StatefulWidget {
|
||||
final List<ShotRecord> shots;
|
||||
final String myTeamName;
|
||||
final String oppTeamName;
|
||||
final List<String> myPlayers;
|
||||
final List<String> oppPlayers;
|
||||
final Map<String, Map<String, int>> playerStats;
|
||||
|
||||
const HeatmapDialog({
|
||||
super.key,
|
||||
required this.shots,
|
||||
required this.myTeamName,
|
||||
required this.oppTeamName,
|
||||
required this.myPlayers,
|
||||
required this.oppPlayers,
|
||||
required this.playerStats,
|
||||
});
|
||||
|
||||
@override
|
||||
State<HeatmapDialog> createState() => _HeatmapDialogState();
|
||||
}
|
||||
|
||||
class _HeatmapDialogState extends State<HeatmapDialog> {
|
||||
bool _isMapVisible = false;
|
||||
String _selectedTeam = '';
|
||||
String _selectedPlayer = '';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Color headerColor = const Color(0xFFE88F15);
|
||||
final Color yellowBackground = const Color(0xFFDFAB00);
|
||||
|
||||
final double screenHeight = MediaQuery.of(context).size.height;
|
||||
final double dialogHeight = screenHeight * 0.95;
|
||||
final double dialogWidth = dialogHeight * 1.0;
|
||||
|
||||
return Dialog(
|
||||
backgroundColor: yellowBackground,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
insetPadding: const EdgeInsets.all(10),
|
||||
child: SizedBox(
|
||||
height: dialogHeight,
|
||||
width: dialogWidth,
|
||||
child: _isMapVisible ? _buildMapScreen(headerColor) : _buildSelectionScreen(headerColor),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// TELA 1: LISTA COM AS DUAS EQUIPAS LADO A LADO
|
||||
// ==========================================
|
||||
Widget _buildSelectionScreen(Color headerColor) {
|
||||
return Column(
|
||||
children: [
|
||||
// CABEÇALHO
|
||||
Container(
|
||||
height: 40,
|
||||
color: headerColor,
|
||||
width: double.infinity,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
"ESCOLHE A EQUIPA OU UM JOGADOR",
|
||||
style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.bold),
|
||||
),
|
||||
Positioned(
|
||||
right: 8,
|
||||
child: InkWell(
|
||||
onTap: () => Navigator.pop(context),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: const BoxDecoration(color: Colors.white, shape: BoxShape.circle),
|
||||
child: Icon(Icons.close, color: headerColor, size: 16),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// CORPO: AS DUAS LISTAS LADO A LADO
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
// 👇 ESQUERDA: COLUNA DA EQUIPA ADVERSÁRIA 👇
|
||||
Expanded(
|
||||
child: _buildTeamColumn(
|
||||
teamName: widget.oppTeamName,
|
||||
players: widget.oppPlayers,
|
||||
teamColor: AppTheme.oppTeamRed, // Vermelho do Tema
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// 👇 DIREITA: COLUNA DA TUA EQUIPA 👇
|
||||
Expanded(
|
||||
child: _buildTeamColumn(
|
||||
teamName: widget.myTeamName,
|
||||
players: widget.myPlayers,
|
||||
teamColor: AppTheme.myTeamBlue, // Azul do Tema
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTeamColumn({required String teamName, required List<String> players, required Color teamColor}) {
|
||||
List<String> realPlayers = players.where((p) => !p.startsWith("Sem ")).toList();
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// CABEÇALHO DA EQUIPA (Botão para ver a equipa toda)
|
||||
InkWell(
|
||||
onTap: () => setState(() {
|
||||
_selectedTeam = teamName;
|
||||
_selectedPlayer = 'Todos';
|
||||
_isMapVisible = true;
|
||||
}),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: teamColor,
|
||||
borderRadius: const BorderRadius.only(topLeft: Radius.circular(8), topRight: Radius.circular(8)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(teamName.toUpperCase(), style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 16)),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 2),
|
||||
decoration: BoxDecoration(color: Colors.white24, borderRadius: BorderRadius.circular(12)),
|
||||
child: const Text("MAPA GERAL DA EQUIPA", style: TextStyle(color: Colors.white, fontSize: 10, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// LISTA DOS JOGADORES COM OS SEUS PONTOS
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
itemCount: realPlayers.length,
|
||||
separatorBuilder: (context, index) => const Divider(height: 1, color: Colors.black12),
|
||||
itemBuilder: (context, index) {
|
||||
String p = realPlayers[index];
|
||||
int pts = widget.playerStats[p]?['pts'] ?? 0;
|
||||
|
||||
return ListTile(
|
||||
dense: true,
|
||||
visualDensity: VisualDensity.compact,
|
||||
leading: Icon(Icons.person, color: teamColor),
|
||||
title: Text(p, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 13, color: Colors.black87)),
|
||||
trailing: Text("$pts Pts", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13, color: teamColor)),
|
||||
onTap: () => setState(() {
|
||||
_selectedTeam = teamName;
|
||||
_selectedPlayer = p;
|
||||
_isMapVisible = true; // Abre o mapa para este jogador!
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// TELA 2: O MAPA DE CALOR DESENHADO
|
||||
// ==========================================
|
||||
Widget _buildMapScreen(Color headerColor) {
|
||||
List<ShotRecord> filteredShots = widget.shots.where((s) {
|
||||
if (_selectedPlayer != 'Todos') return s.playerName == _selectedPlayer;
|
||||
if (_selectedTeam == widget.myTeamName) return widget.myPlayers.contains(s.playerName);
|
||||
if (_selectedTeam == widget.oppTeamName) return widget.oppPlayers.contains(s.playerName);
|
||||
return true;
|
||||
}).toList();
|
||||
|
||||
String titleText = _selectedPlayer == 'Todos'
|
||||
? "MAPA GERAL: ${_selectedTeam.toUpperCase()}"
|
||||
: "MAPA: ${_selectedPlayer.toUpperCase()}";
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// CABEÇALHO COM BOTÃO VOLTAR
|
||||
Container(
|
||||
height: 40,
|
||||
color: headerColor,
|
||||
width: double.infinity,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Positioned(
|
||||
left: 8,
|
||||
child: InkWell(
|
||||
onTap: () => setState(() => _isMapVisible = false), // Botão de voltar ao menu de seleção!
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(12)),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.arrow_back, color: headerColor, size: 14),
|
||||
const SizedBox(width: 4),
|
||||
Text("VOLTAR", style: TextStyle(color: headerColor, fontWeight: FontWeight.bold, fontSize: 12)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
titleText,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.bold),
|
||||
),
|
||||
Positioned(
|
||||
right: 8,
|
||||
child: InkWell(
|
||||
onTap: () => Navigator.pop(context), // Fecha o popup todo
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: const BoxDecoration(color: Colors.white, shape: BoxShape.circle),
|
||||
child: Icon(Icons.close, color: headerColor, size: 16),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// O DESENHO DO CAMPO E AS BOLAS
|
||||
Expanded(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return Stack(
|
||||
children: [
|
||||
CustomPaint(size: Size(constraints.maxWidth, constraints.maxHeight), painter: HeatmapCourtPainter()),
|
||||
...filteredShots.map((shot) => Positioned(
|
||||
left: (shot.relativeX * constraints.maxWidth) - 8,
|
||||
top: (shot.relativeY * constraints.maxHeight) - 8,
|
||||
child: CircleAvatar(
|
||||
radius: 8,
|
||||
backgroundColor: shot.isMake ? AppTheme.successGreen : AppTheme.actionMiss,
|
||||
child: Icon(shot.isMake ? Icons.check : Icons.close, size: 10, color: Colors.white)
|
||||
),
|
||||
)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HeatmapCourtPainter extends CustomPainter {
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final double w = size.width;
|
||||
final double h = size.height;
|
||||
final double basketX = w / 2;
|
||||
|
||||
final Paint whiteStroke = Paint()..color = Colors.white..style = PaintingStyle.stroke..strokeWidth = 2.0;
|
||||
final Paint blackStroke = Paint()..color = Colors.black87..style = PaintingStyle.stroke..strokeWidth = 2.0;
|
||||
|
||||
final double margin = w * 0.10;
|
||||
final double length = h * 0.35;
|
||||
final double larguraDoArco = (w / 2) - margin;
|
||||
final double alturaDoArco = larguraDoArco * 0.30;
|
||||
final double totalArcoHeight = alturaDoArco * 4;
|
||||
|
||||
canvas.drawLine(Offset(margin, 0), Offset(margin, length), whiteStroke);
|
||||
canvas.drawLine(Offset(w - margin, 0), Offset(w - margin, length), whiteStroke);
|
||||
canvas.drawLine(Offset(0, length), Offset(margin, length), whiteStroke);
|
||||
canvas.drawLine(Offset(w - margin, length), Offset(w, length), whiteStroke);
|
||||
canvas.drawArc(Rect.fromCenter(center: Offset(basketX, length), width: larguraDoArco * 2, height: totalArcoHeight), 0, math.pi, false, whiteStroke);
|
||||
|
||||
double sXL = basketX + (larguraDoArco * math.cos(math.pi * 0.75));
|
||||
double sYL = length + ((totalArcoHeight / 2) * math.sin(math.pi * 0.75));
|
||||
double sXR = basketX + (larguraDoArco * math.cos(math.pi * 0.25));
|
||||
double sYR = length + ((totalArcoHeight / 2) * math.sin(math.pi * 0.25));
|
||||
|
||||
canvas.drawLine(Offset(sXL, sYL), Offset(0, h * 0.85), whiteStroke);
|
||||
canvas.drawLine(Offset(sXR, sYR), Offset(w, h * 0.85), whiteStroke);
|
||||
|
||||
final double pW = w * 0.28;
|
||||
final double pH = h * 0.38;
|
||||
canvas.drawRect(Rect.fromLTWH(basketX - pW / 2, 0, pW, pH), blackStroke);
|
||||
|
||||
final double ftR = pW / 2;
|
||||
canvas.drawArc(Rect.fromCircle(center: Offset(basketX, pH), radius: ftR), 0, math.pi, false, blackStroke);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
canvas.drawArc(Rect.fromCircle(center: Offset(basketX, pH), radius: ftR), math.pi + (i * 2 * (math.pi / 20)), math.pi / 20, false, blackStroke);
|
||||
}
|
||||
|
||||
canvas.drawLine(Offset(basketX - pW / 2, pH), Offset(sXL, sYL), blackStroke);
|
||||
canvas.drawLine(Offset(basketX + pW / 2, pH), Offset(sXR, sYR), blackStroke);
|
||||
|
||||
canvas.drawArc(Rect.fromCircle(center: Offset(basketX, h), radius: w * 0.12), math.pi, math.pi, false, blackStroke);
|
||||
canvas.drawCircle(Offset(basketX, h * 0.12), w * 0.02, blackStroke);
|
||||
canvas.drawLine(Offset(basketX - w * 0.08, h * 0.12 - 5), Offset(basketX + w * 0.08, h * 0.12 - 5), blackStroke);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
|
||||
}
|
||||
@@ -4,12 +4,14 @@ import 'dart:math' as math;
|
||||
class ZoneMapDialog extends StatelessWidget {
|
||||
final String playerName;
|
||||
final bool isMake;
|
||||
final bool is3PointAction; // 👇 AGORA O POP-UP SABE O QUE ARRASTASTE!
|
||||
final Function(String zone, int points, double relativeX, double relativeY) onZoneSelected;
|
||||
|
||||
const ZoneMapDialog({
|
||||
super.key,
|
||||
required this.playerName,
|
||||
required this.isMake,
|
||||
required this.is3PointAction,
|
||||
required this.onZoneSelected,
|
||||
});
|
||||
|
||||
@@ -32,7 +34,6 @@ class ZoneMapDialog extends StatelessWidget {
|
||||
width: dialogWidth,
|
||||
child: Column(
|
||||
children: [
|
||||
// CABEÇALHO
|
||||
Container(
|
||||
height: 40,
|
||||
color: headerColor,
|
||||
@@ -58,7 +59,6 @@ class ZoneMapDialog extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
// MAPA INTERATIVO
|
||||
Expanded(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
@@ -66,7 +66,7 @@ class ZoneMapDialog extends StatelessWidget {
|
||||
onTapUp: (details) => _calculateAndReturnZone(context, details.localPosition, constraints.biggest),
|
||||
child: CustomPaint(
|
||||
size: Size(constraints.maxWidth, constraints.maxHeight),
|
||||
painter: DebugPainter(),
|
||||
painter: DebugPainter(is3PointAction: is3PointAction), // 👇 Passa a info para o desenhador
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -78,24 +78,23 @@ class ZoneMapDialog extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
void _calculateAndReturnZone(BuildContext context, Offset tap, Size size) {
|
||||
void _calculateAndReturnZone(BuildContext context, Offset tap, Size size) {
|
||||
final double w = size.width;
|
||||
final double h = size.height;
|
||||
final double x = tap.dx;
|
||||
final double y = tap.dy;
|
||||
final double basketX = w / 2;
|
||||
|
||||
// MESMAS MEDIDAS DO PAINTER
|
||||
final double margin = w * 0.10;
|
||||
final double length = h * 0.35;
|
||||
final double larguraDoArco = (w / 2) - margin;
|
||||
final double alturaDoArco = larguraDoArco * 0.30;
|
||||
final double totalArcoHeight = alturaDoArco * 4;
|
||||
|
||||
String zone = "Meia Distância";
|
||||
String zone = "";
|
||||
int pts = 2;
|
||||
|
||||
// 1. TESTE DE 3 PONTOS
|
||||
// 1. SABER SE CLICOU NA ZONA DE 3 OU DE 2
|
||||
bool is3 = false;
|
||||
if (y < length) {
|
||||
if (x < margin || x > w - margin) is3 = true;
|
||||
@@ -106,33 +105,52 @@ class ZoneMapDialog extends StatelessWidget {
|
||||
if (ellipse > 1.0) is3 = true;
|
||||
}
|
||||
|
||||
// 👇 MAGIA AQUI: BLOQUEIA O CLIQUE NA ZONA ESCURA! 👇
|
||||
if (is3PointAction && !is3) return; // Arrastou 3pts mas clicou na de 2pts -> IGNORA
|
||||
if (!is3PointAction && is3) return; // Arrastou 2pts mas clicou na de 3pts -> IGNORA
|
||||
|
||||
double angle = math.atan2(y - length, x - basketX);
|
||||
|
||||
if (is3) {
|
||||
pts = 3;
|
||||
double angle = math.atan2(y - length, x - basketX);
|
||||
if (y < length) {
|
||||
zone = (x < w / 2) ? "Canto Esquerdo" : "Canto Direito";
|
||||
zone = (x < w / 2) ? "Canto Esquerdo (3pt)" : "Canto Direito (3pt)";
|
||||
} else if (angle > 2.35) {
|
||||
zone = "Ala Esquerda";
|
||||
zone = "Ala Esquerda (3pt)";
|
||||
} else if (angle < 0.78) {
|
||||
zone = "Ala Direita";
|
||||
zone = "Ala Direita (3pt)";
|
||||
} else {
|
||||
zone = "Topo (3pts)";
|
||||
zone = "Topo (3pt)";
|
||||
}
|
||||
} else {
|
||||
// 2. TESTE DE GARRAFÃO
|
||||
pts = 2;
|
||||
final double pW = w * 0.28;
|
||||
final double pH = h * 0.38;
|
||||
if (x > basketX - pW / 2 && x < basketX + pW / 2 && y < pH) {
|
||||
zone = "Garrafão";
|
||||
} else {
|
||||
if (y < length) {
|
||||
zone = (x < w / 2) ? "Meia Distância (Canto Esq)" : "Meia Distância (Canto Dir)";
|
||||
} else if (angle > 2.35) {
|
||||
zone = "Meia Distância (Esq)";
|
||||
} else if (angle < 0.78) {
|
||||
zone = "Meia Distância (Dir)";
|
||||
} else {
|
||||
zone = "Meia Distância (Centro)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 👇 A MUDANÇA ESTÁ AQUI! Passamos os dados e deixamos quem chamou decidir como fechar!
|
||||
onZoneSelected(zone, pts, x / w, y / h);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DebugPainter extends CustomPainter {
|
||||
final bool is3PointAction;
|
||||
|
||||
DebugPainter({required this.is3PointAction});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final double w = size.width;
|
||||
@@ -148,41 +166,63 @@ class DebugPainter extends CustomPainter {
|
||||
final double alturaDoArco = larguraDoArco * 0.30;
|
||||
final double totalArcoHeight = alturaDoArco * 4;
|
||||
|
||||
// 3 PONTOS (BRANCO)
|
||||
// DESENHA O CAMPO
|
||||
canvas.drawLine(Offset(margin, 0), Offset(margin, length), whiteStroke);
|
||||
canvas.drawLine(Offset(w - margin, 0), Offset(w - margin, length), whiteStroke);
|
||||
canvas.drawLine(Offset(0, length), Offset(margin, length), whiteStroke);
|
||||
canvas.drawLine(Offset(w - margin, length), Offset(w, length), whiteStroke);
|
||||
canvas.drawArc(Rect.fromCenter(center: Offset(basketX, length), width: larguraDoArco * 2, height: totalArcoHeight), 0, math.pi, false, whiteStroke);
|
||||
|
||||
// DIVISÕES 45º (BRANCO)
|
||||
double sXL = basketX + (larguraDoArco * math.cos(math.pi * 0.75));
|
||||
double sYL = length + ((totalArcoHeight / 2) * math.sin(math.pi * 0.75));
|
||||
double sXR = basketX + (larguraDoArco * math.cos(math.pi * 0.25));
|
||||
double sYR = length + ((totalArcoHeight / 2) * math.sin(math.pi * 0.25));
|
||||
|
||||
canvas.drawLine(Offset(sXL, sYL), Offset(0, h * 0.85), whiteStroke);
|
||||
canvas.drawLine(Offset(sXR, sYR), Offset(w, h * 0.85), whiteStroke);
|
||||
|
||||
// GARRAFÃO E MEIO CAMPO (PRETO)
|
||||
final double pW = w * 0.28;
|
||||
final double pH = h * 0.38;
|
||||
canvas.drawRect(Rect.fromLTWH(basketX - pW / 2, 0, pW, pH), blackStroke);
|
||||
|
||||
final double ftR = pW / 2;
|
||||
canvas.drawArc(Rect.fromCircle(center: Offset(basketX, pH), radius: ftR), 0, math.pi, false, blackStroke);
|
||||
|
||||
// Tracejado
|
||||
const int dashCount = 10;
|
||||
for (int i = 0; i < dashCount; i++) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
canvas.drawArc(Rect.fromCircle(center: Offset(basketX, pH), radius: ftR), math.pi + (i * 2 * (math.pi / 20)), math.pi / 20, false, blackStroke);
|
||||
}
|
||||
|
||||
canvas.drawArc(Rect.fromCircle(center: Offset(basketX, h), radius: w * 0.12), math.pi, math.pi, false, blackStroke);
|
||||
canvas.drawLine(Offset(basketX - pW / 2, pH), Offset(sXL, sYL), blackStroke);
|
||||
canvas.drawLine(Offset(basketX + pW / 2, pH), Offset(sXR, sYR), blackStroke);
|
||||
|
||||
// CESTO
|
||||
canvas.drawArc(Rect.fromCircle(center: Offset(basketX, h), radius: w * 0.12), math.pi, math.pi, false, blackStroke);
|
||||
canvas.drawCircle(Offset(basketX, h * 0.12), w * 0.02, blackStroke);
|
||||
canvas.drawLine(Offset(basketX - w * 0.08, h * 0.12 - 5), Offset(basketX + w * 0.08, h * 0.12 - 5), blackStroke);
|
||||
|
||||
// ==========================================
|
||||
// 👇 EFEITO DE ESCURECIMENTO (SHADOW) 👇
|
||||
// ==========================================
|
||||
final Paint shadowPaint = Paint()..color = Colors.black.withOpacity(0.75); // 75% escuro!
|
||||
|
||||
// Cria o molde da área de 2 pontos
|
||||
Path path2pt = Path();
|
||||
path2pt.moveTo(margin, 0);
|
||||
path2pt.lineTo(margin, length);
|
||||
// Faz o arco curvo da linha de 3 pontos
|
||||
path2pt.arcTo(Rect.fromCenter(center: Offset(basketX, length), width: larguraDoArco * 2, height: totalArcoHeight), math.pi, -math.pi, false);
|
||||
path2pt.lineTo(w - margin, 0);
|
||||
path2pt.close();
|
||||
|
||||
if (is3PointAction) {
|
||||
// Arrastou 3 Pontos -> Escurece a Zona de 2!
|
||||
canvas.drawPath(path2pt, shadowPaint);
|
||||
} else {
|
||||
// Arrastou 2 Pontos -> Escurece a Zona de 3!
|
||||
Path fullScreen = Path()..addRect(Rect.fromLTWH(0, 0, w, h));
|
||||
Path path3pt = Path.combine(PathOperation.difference, fullScreen, path2pt);
|
||||
canvas.drawPath(path3pt, shadowPaint);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(CustomPainter old) => false;
|
||||
bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
|
||||
}
|
||||
Reference in New Issue
Block a user