eliminar e tentativa de partilhar

This commit is contained in:
2026-04-04 01:28:47 +01:00
parent 1b08ed7d07
commit 2544e52636
5 changed files with 169 additions and 56 deletions

View File

@@ -78,7 +78,7 @@ class PlacarController extends ChangeNotifier {
String? pendingPlayerId;
List<ShotRecord> matchShots = [];
// 👇 LISTA PARA O HISTÓRICO (PLAY-BY-PLAY)
// Lista para o Histórico de Jogadas
List<String> playByPlay = [];
ValueNotifier<Duration> durationNotifier = ValueNotifier(const Duration(minutes: 10));
@@ -113,6 +113,13 @@ class PlacarController extends ChangeNotifier {
gameWasAlreadyFinished = gameResponse['status'] == 'Terminado';
// CARREGAR HISTÓRICO DA BASE DE DADOS
if (gameResponse['play_by_play'] != null) {
playByPlay = List<String>.from(gameResponse['play_by_play']);
} else {
playByPlay = [];
}
final teamsResponse = await supabase.from('teams').select('id, name').inFilter('name', [myTeam, opponentTeam]);
for (var t in teamsResponse) {
if (t['name'] == myTeam) myTeamDbId = t['id'];
@@ -224,7 +231,7 @@ class PlacarController extends ChangeNotifier {
'playerStats': playerStats,
'myCourt': myCourt, 'myBench': myBench, 'oppCourt': oppCourt, 'oppBench': oppBench,
'matchShots': matchShots.map((s) => s.toJson()).toList(),
'playByPlay': playByPlay, // 👇 Guarda o histórico
'playByPlay': playByPlay, // Guarda o histórico no telemóvel
};
await prefs.setString('backup_$gameId', jsonEncode(backupData));
} catch (e) {
@@ -254,7 +261,7 @@ class PlacarController extends ChangeNotifier {
List<dynamic> decodedShots = data['matchShots'];
matchShots = decodedShots.map((s) => ShotRecord.fromJson(s)).toList();
playByPlay = List<String>.from(data['playByPlay'] ?? []); // 👇 Carrega o histórico
playByPlay = List<String>.from(data['playByPlay'] ?? []);
debugPrint("🔄 AUTO-SAVE RECUPERADO COM SUCESSO!");
}
@@ -346,23 +353,22 @@ class PlacarController extends ChangeNotifier {
void registerShotFromPopup(BuildContext context, String action, String targetPlayer, String zone, int points, double relativeX, double relativeY) {
String playerId = targetPlayer.replaceAll("player_my_", "").replaceAll("player_opp_", "");
bool isMyTeam = targetPlayer.startsWith("player_my_");
bool isMake = action.startsWith("add_");
String name = playerNames[playerId]!;
String name = playerNames[playerId] ?? "Jogador";
if (playerStats.containsKey(playerId)) {
playerStats[playerId]!['fga'] = playerStats[playerId]!['fga']! + 1;
matchShots.add(ShotRecord(
relativeX: relativeX,
relativeY: relativeY,
isMake: isMake,
playerId: playerId,
playerName: name,
zone: zone,
points: points
));
if (isMake) {
playerStats[playerId]!['fgm'] = playerStats[playerId]!['fgm']! + 1;
playerStats[playerId]!['pts'] = playerStats[playerId]!['pts']! + points;
if (isMyTeam) myScore += points; else opponentScore += points;
}
}
String finalAction = isMake ? "add_pts_$points" : "miss_$points";
commitStat(finalAction, targetPlayer);
matchShots.add(ShotRecord(relativeX: relativeX, relativeY: relativeY, isMake: isMake, playerId: playerId, playerName: name, zone: zone, points: points));
_saveLocalBackup();
notifyListeners();
}
@@ -457,7 +463,18 @@ class PlacarController extends ChangeNotifier {
else if (action == "miss_2" || action == "miss_3") { stats["fga"] = stats["fga"]! + 1; logText = "falhou lançamento ❌"; }
else if (action == "add_orb") { stats["orb"] = stats["orb"]! + 1; stats["rbs"] = stats["rbs"]! + 1; logText = "ganhou ressalto ofensivo 🔄"; }
else if (action == "add_drb") { stats["drb"] = stats["drb"]! + 1; stats["rbs"] = stats["rbs"]! + 1; logText = "ganhou ressalto defensivo 🛡️"; }
else if (action == "add_ast") { stats["ast"] = stats["ast"]! + 1; logText = "fez uma assistência 🤝"; }
else if (action == "add_ast") {
stats["ast"] = stats["ast"]! + 1;
if (playByPlay.isNotEmpty && playByPlay[0].contains("marcou") && !playByPlay[0].contains("Assistência")) {
playByPlay[0] = "${playByPlay[0]} (Assistência: $name 🤝)";
_saveLocalBackup();
notifyListeners();
return;
} else {
logText = "fez uma assistência 🤝";
}
}
else if (action == "add_stl") { stats["stl"] = stats["stl"]! + 1; logText = "roubou a bola 🥷"; }
else if (action == "add_tov") { stats["tov"] = stats["tov"]! + 1; logText = "perdeu a bola (turnover) 🤦"; }
else if (action == "add_blk") { stats["blk"] = stats["blk"]! + 1; logText = "fez um desarme (bloco) ✋"; }
@@ -514,6 +531,7 @@ class PlacarController extends ChangeNotifier {
if (mvpScore > maxMvpScore && mvpScore > 0) { maxMvpScore = mvpScore; mvpName = pName; }
});
// ATUALIZA O JOGO COM OS NOVOS ESTADOS E COM O HISTÓRICO DE JOGADAS!
await supabase.from('games').update({
'my_score': myScore,
'opponent_score': opponentScore,
@@ -527,6 +545,7 @@ class PlacarController extends ChangeNotifier {
'top_rbs_name': topRbsName,
'top_def_name': topDefName,
'mvp_name': mvpName,
'play_by_play': playByPlay, // Envia o histórico para a base de dados
}).eq('id', gameId);
if (isGameFinishedNow && !gameWasAlreadyFinished && myTeamDbId != null && oppTeamDbId != null) {