mapa de calor ?

This commit is contained in:
2026-03-12 16:12:02 +00:00
parent b95d6dc8d4
commit cae3bbfe3b
8 changed files with 450 additions and 574 deletions

View File

@@ -3,9 +3,17 @@ import 'package:flutter/material.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
class ShotRecord {
final Offset position;
final double relativeX;
final double relativeY;
final bool isMake;
ShotRecord(this.position, this.isMake);
final String playerName; // Bónus: Agora guardamos quem foi o jogador!
ShotRecord({
required this.relativeX,
required this.relativeY,
required this.isMake,
required this.playerName
});
}
class PlacarController {
@@ -261,7 +269,7 @@ class PlacarController {
onUpdate();
}
void registerShotLocation(BuildContext context, Offset position, Size size) {
void registerShotLocation(BuildContext context, Offset position, Size size) {
if (pendingAction == null || pendingPlayer == null) return;
bool is3Pt = pendingAction!.contains("_3");
bool is2Pt = pendingAction!.contains("_2");
@@ -269,13 +277,28 @@ class PlacarController {
if (is3Pt || is2Pt) {
bool isValid = _validateShotZone(position, size, is3Pt);
if (!isValid) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('🛑 Local de lançamento incompatível com a pontuação.'), backgroundColor: Colors.red, duration: Duration(seconds: 2)));
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('🛑 Local incompatível com a pontuação.'), backgroundColor: Colors.red, duration: Duration(seconds: 2)));
return;
}
}
bool isMake = pendingAction!.startsWith("add_pts_");
matchShots.add(ShotRecord(position, isMake));
// 👇 A MÁGICA DAS COORDENADAS RELATIVAS (0.0 a 1.0) 👇
double relX = position.dx / size.width;
double relY = position.dy / size.height;
// Extrai só o nome do jogador
String name = pendingPlayer!.replaceAll("player_my_", "").replaceAll("player_opp_", "");
// Guarda na lista!
matchShots.add(ShotRecord(
relativeX: relX,
relativeY: relY,
isMake: isMake,
playerName: name
));
commitStat(pendingAction!, pendingPlayer!);
isSelectingShotLocation = false;