assist
This commit is contained in:
@@ -1,15 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:playmaker/classe/theme.dart';
|
||||
import 'package:playmaker/controllers/placar_controller.dart';
|
||||
import '../classe/theme.dart';
|
||||
import '../controllers/placar_controller.dart';
|
||||
import 'package:playmaker/zone_map_dialog.dart';
|
||||
import 'dart:math' as math;
|
||||
|
||||
// ============================================================================
|
||||
// 1. PLACAR SUPERIOR (CRONÓMETRO E RESULTADO)
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
// 1. PLACAR SUPERIOR (COM CRONÓMETRO DE ALTA PERFORMANCE)
|
||||
// ============================================================================
|
||||
// POP-UP DE ASSISTÊNCIA
|
||||
void showAssistDialog(BuildContext context, PlacarController controller, bool isOpponent, String scorerId, double sf) {
|
||||
final teamCourt = isOpponent ? controller.oppCourt : controller.myCourt;
|
||||
final prefix = isOpponent ? "player_opp_" : "player_my_";
|
||||
|
||||
final possibleAssistants = teamCourt.where((id) => id != scorerId && !id.startsWith("fake_")).toList();
|
||||
|
||||
if (possibleAssistants.isEmpty) return;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15 * sf)),
|
||||
title: Text("Houve Assistência?", style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontWeight: FontWeight.bold, fontSize: 18 * sf)),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
...possibleAssistants.map((id) {
|
||||
final name = controller.playerNames[id] ?? "Desconhecido";
|
||||
final number = controller.playerNumbers[id] ?? "0";
|
||||
return ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: isOpponent ? AppTheme.oppTeamRed : AppTheme.myTeamBlue,
|
||||
child: Text(number, style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
title: Text(name, style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontWeight: FontWeight.bold)),
|
||||
onTap: () {
|
||||
Navigator.pop(ctx);
|
||||
controller.commitStat("add_ast", "$prefix$id");
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Assistência: $name'), duration: const Duration(seconds: 1), backgroundColor: AppTheme.successGreen));
|
||||
},
|
||||
);
|
||||
}),
|
||||
Divider(color: Colors.grey.withOpacity(0.3)),
|
||||
ListTile(
|
||||
leading: const CircleAvatar(backgroundColor: Colors.grey, child: Icon(Icons.person_off, color: Colors.white)),
|
||||
title: Text("Isolado (Sem assistência)", style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontStyle: FontStyle.italic)),
|
||||
onTap: () => Navigator.pop(ctx),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 1. PLACAR SUPERIOR
|
||||
class TopScoreboard extends StatelessWidget {
|
||||
final PlacarController controller;
|
||||
final double sf;
|
||||
@@ -36,7 +79,6 @@ class TopScoreboard extends StatelessWidget {
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 14 * sf, vertical: 4 * sf),
|
||||
decoration: BoxDecoration(color: AppTheme.placarTimerBg, borderRadius: BorderRadius.circular(9 * sf)),
|
||||
// 👇 AQUI ESTÁ A MAGIA DE PERFORMANCE! Só este texto se atualiza a cada segundo! 👇
|
||||
child: ValueListenableBuilder<Duration>(
|
||||
valueListenable: controller.durationNotifier,
|
||||
builder: (context, duration, child) {
|
||||
@@ -87,59 +129,7 @@ class TopScoreboard extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
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: 2.5 * sf),
|
||||
width: 10 * sf, height: 10 * sf,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: index < timeouts ? AppTheme.warningAmber : Colors.grey.shade600,
|
||||
border: Border.all(color: Colors.white54, width: 1.0 * sf)
|
||||
),
|
||||
)),
|
||||
);
|
||||
|
||||
List<Widget> content = [
|
||||
Column(
|
||||
children: [
|
||||
_scoreBox(score, color, sf),
|
||||
SizedBox(height: 5 * sf),
|
||||
timeoutIndicators
|
||||
]
|
||||
),
|
||||
SizedBox(width: 12 * sf),
|
||||
Column(
|
||||
crossAxisAlignment: isOpp ? CrossAxisAlignment.start : CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
name.toUpperCase(),
|
||||
style: TextStyle(color: Colors.white, fontSize: 16 * sf, fontWeight: FontWeight.w900, letterSpacing: 1.0 * sf)
|
||||
),
|
||||
SizedBox(height: 3 * sf),
|
||||
Text(
|
||||
"FALTAS: $displayFouls",
|
||||
style: TextStyle(color: displayFouls >= 5 ? AppTheme.actionMiss : AppTheme.warningAmber, fontSize: 11 * 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: 45 * sf, height: 35 * sf,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(6 * sf)),
|
||||
child: Text(score.toString(), style: TextStyle(color: Colors.white, fontSize: 20 * sf, fontWeight: FontWeight.w900)),
|
||||
);
|
||||
// ============================================================================
|
||||
// 2. BANCO DE SUPLENTES (COM TRADUTOR DE NOME)
|
||||
// ============================================================================
|
||||
// 2. BANCO DE SUPLENTES
|
||||
class BenchPlayersList extends StatelessWidget {
|
||||
final PlacarController controller;
|
||||
final bool isOpponent;
|
||||
@@ -201,9 +191,7 @@ class BenchPlayersList extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 3. CARTÃO DO JOGADOR NO CAMPO (COM TRADUTOR DE NOME)
|
||||
// ============================================================================
|
||||
// 3. CARTÃO DO JOGADOR NO CAMPO
|
||||
class PlayerCourtCard extends StatelessWidget {
|
||||
final PlacarController controller;
|
||||
final String playerId;
|
||||
@@ -249,6 +237,7 @@ class PlayerCourtCard extends StatelessWidget {
|
||||
onZoneSelected: (zone, points, relX, relY) {
|
||||
Navigator.pop(ctx);
|
||||
controller.registerShotFromPopup(context, action, "$prefix$playerId", zone, points, relX, relY);
|
||||
if (isMake) showAssistDialog(context, controller, isOpponent, playerId, sf);
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -318,9 +307,7 @@ class PlayerCourtCard extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 4. PAINEL DE BOTÕES DE AÇÃO
|
||||
// ============================================================================
|
||||
class ActionButtonsPanel extends StatelessWidget {
|
||||
final PlacarController controller;
|
||||
final double sf;
|
||||
@@ -454,323 +441,4 @@ class ActionButtonsPanel extends StatelessWidget {
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// MAPA DE CALOR
|
||||
// ============================================================================
|
||||
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 TUA EQUIPA (AZUL) 👇
|
||||
Expanded(
|
||||
child: _buildTeamColumn(
|
||||
teamName: widget.myTeamName,
|
||||
players: widget.myPlayers,
|
||||
teamColor: AppTheme.myTeamBlue,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// 👇 DIREITA: COLUNA DA EQUIPA ADVERSÁRIA (VERMELHA) 👇
|
||||
Expanded(
|
||||
child: _buildTeamColumn(
|
||||
teamName: widget.oppTeamName,
|
||||
players: widget.oppPlayers,
|
||||
teamColor: AppTheme.oppTeamRed,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
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: [
|
||||
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)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
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;
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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: [
|
||||
Container(
|
||||
height: 40,
|
||||
color: headerColor,
|
||||
width: double.infinity,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Positioned(
|
||||
left: 8,
|
||||
child: InkWell(
|
||||
onTap: () => setState(() => _isMapVisible = false),
|
||||
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),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: const BoxDecoration(color: Colors.white, shape: BoxShape.circle),
|
||||
child: Icon(Icons.close, color: headerColor, size: 16),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return Stack(
|
||||
children: [
|
||||
// 👇 A MÁGICA: O CAMPO DESENHADO IGUAL AO POP-UP (CustomPaint) 👇
|
||||
CustomPaint(
|
||||
size: Size(constraints.maxWidth, constraints.maxHeight),
|
||||
painter: HeatmapCourtPainter(),
|
||||
),
|
||||
// AS BOLINHAS DOS LANÇAMENTOS POR CIMA DAS LINHAS
|
||||
...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)
|
||||
),
|
||||
)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 👇 O PINTOR QUE DESENHA AS LINHAS PERFEITAS DO CAMPO 👇
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user