fazer pdf

This commit is contained in:
2026-04-14 17:19:21 +01:00
parent 2544e52636
commit fb85566e3f
10 changed files with 544 additions and 35 deletions

View File

@@ -78,7 +78,6 @@ class PlacarController extends ChangeNotifier {
String? pendingPlayerId;
List<ShotRecord> matchShots = [];
// Lista para o Histórico de Jogadas
List<String> playByPlay = [];
ValueNotifier<Duration> durationNotifier = ValueNotifier(const Duration(minutes: 10));
@@ -113,7 +112,6 @@ 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 {
@@ -147,6 +145,7 @@ class PlacarController extends ChangeNotifier {
"stl": s['stl'] ?? 0, "tov": s['tov'] ?? 0, "blk": s['blk'] ?? 0,
"fls": s['fls'] ?? 0, "fgm": s['fgm'] ?? 0, "fga": s['fga'] ?? 0,
"ftm": s['ftm'] ?? 0, "fta": s['fta'] ?? 0, "orb": s['orb'] ?? 0, "drb": s['drb'] ?? 0,
"p2m": s['p2m'] ?? 0, "p2a": s['p2a'] ?? 0, "p3m": s['p3m'] ?? 0, "p3a": s['p3a'] ?? 0,
};
myFouls += (s['fls'] as int? ?? 0);
}
@@ -166,6 +165,7 @@ class PlacarController extends ChangeNotifier {
"stl": s['stl'] ?? 0, "tov": s['tov'] ?? 0, "blk": s['blk'] ?? 0,
"fls": s['fls'] ?? 0, "fgm": s['fgm'] ?? 0, "fga": s['fga'] ?? 0,
"ftm": s['ftm'] ?? 0, "fta": s['fta'] ?? 0, "orb": s['orb'] ?? 0, "drb": s['drb'] ?? 0,
"p2m": s['p2m'] ?? 0, "p2a": s['p2a'] ?? 0, "p3m": s['p3m'] ?? 0, "p3a": s['p3a'] ?? 0,
};
opponentFouls += (s['fls'] as int? ?? 0);
}
@@ -204,7 +204,8 @@ class PlacarController extends ChangeNotifier {
playerStats[id] = {
"pts": 0, "rbs": 0, "ast": 0, "stl": 0, "tov": 0, "blk": 0,
"fls": 0, "fgm": 0, "fga": 0, "ftm": 0, "fta": 0, "orb": 0, "drb": 0
"fls": 0, "fgm": 0, "fga": 0, "ftm": 0, "fta": 0, "orb": 0, "drb": 0,
"p2m": 0, "p2a": 0, "p3m": 0, "p3a": 0
};
if (isMyTeam) {
@@ -231,7 +232,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 no telemóvel
'playByPlay': playByPlay,
};
await prefs.setString('backup_$gameId', jsonEncode(backupData));
} catch (e) {
@@ -357,13 +358,8 @@ class PlacarController extends ChangeNotifier {
String name = playerNames[playerId] ?? "Jogador";
matchShots.add(ShotRecord(
relativeX: relativeX,
relativeY: relativeY,
isMake: isMake,
playerId: playerId,
playerName: name,
zone: zone,
points: points
relativeX: relativeX, relativeY: relativeY, isMake: isMake,
playerId: playerId, playerName: name, zone: zone, points: points
));
String finalAction = isMake ? "add_pts_$points" : "miss_$points";
@@ -440,8 +436,11 @@ class PlacarController extends ChangeNotifier {
int pts = int.parse(action.split("_").last);
if (isOpponent) opponentScore += pts; else myScore += pts;
stats["pts"] = stats["pts"]! + pts;
if (pts == 2 || pts == 3) { stats["fgm"] = stats["fgm"]! + 1; stats["fga"] = stats["fga"]! + 1; }
if (pts == 2) { stats["fgm"] = stats["fgm"]! + 1; stats["fga"] = stats["fga"]! + 1; stats["p2m"] = stats["p2m"]! + 1; stats["p2a"] = stats["p2a"]! + 1; }
if (pts == 3) { stats["fgm"] = stats["fgm"]! + 1; stats["fga"] = stats["fga"]! + 1; stats["p3m"] = stats["p3m"]! + 1; stats["p3a"] = stats["p3a"]! + 1; }
if (pts == 1) { stats["ftm"] = stats["ftm"]! + 1; stats["fta"] = stats["fta"]! + 1; }
logText = "marcou $pts pontos 🏀";
}
else if (action.startsWith("sub_pts_")) {
@@ -449,9 +448,18 @@ class PlacarController extends ChangeNotifier {
if (isOpponent) { opponentScore = (opponentScore - pts < 0) ? 0 : opponentScore - pts; }
else { myScore = (myScore - pts < 0) ? 0 : myScore - pts; }
stats["pts"] = (stats["pts"]! - pts < 0) ? 0 : stats["pts"]! - pts;
if (pts == 2 || pts == 3) {
if (pts == 2) {
if (stats["fgm"]! > 0) stats["fgm"] = stats["fgm"]! - 1;
if (stats["fga"]! > 0) stats["fga"] = stats["fga"]! - 1;
if (stats["p2m"]! > 0) stats["p2m"] = stats["p2m"]! - 1;
if (stats["p2a"]! > 0) stats["p2a"] = stats["p2a"]! - 1;
}
if (pts == 3) {
if (stats["fgm"]! > 0) stats["fgm"] = stats["fgm"]! - 1;
if (stats["fga"]! > 0) stats["fga"] = stats["fga"]! - 1;
if (stats["p3m"]! > 0) stats["p3m"] = stats["p3m"]! - 1;
if (stats["p3a"]! > 0) stats["p3a"] = stats["p3a"]! - 1;
}
if (pts == 1) {
if (stats["ftm"]! > 0) stats["ftm"] = stats["ftm"]! - 1;
@@ -460,12 +468,12 @@ class PlacarController extends ChangeNotifier {
logText = "teve $pts pontos retirados ❌";
}
else if (action == "miss_1") { stats["fta"] = stats["fta"]! + 1; logText = "falhou lance livre ❌"; }
else if (action == "miss_2" || action == "miss_3") { stats["fga"] = stats["fga"]! + 1; logText = "falhou lançamento ❌"; }
else if (action == "miss_2") { stats["fga"] = stats["fga"]! + 1; stats["p2a"] = stats["p2a"]! + 1; logText = "falhou lançamento de 2 "; }
else if (action == "miss_3") { stats["fga"] = stats["fga"]! + 1; stats["p3a"] = stats["p3a"]! + 1; logText = "falhou lançamento de 3 ❌"; }
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;
if (playByPlay.isNotEmpty && playByPlay[0].contains("marcou") && !playByPlay[0].contains("Assistência")) {
playByPlay[0] = "${playByPlay[0]} (Assistência: $name 🤝)";
_saveLocalBackup();
@@ -531,7 +539,6 @@ 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,
@@ -545,7 +552,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
'play_by_play': playByPlay,
}).eq('id', gameId);
if (isGameFinishedNow && !gameWasAlreadyFinished && myTeamDbId != null && oppTeamDbId != null) {
@@ -579,6 +586,7 @@ class PlacarController extends ChangeNotifier {
batchStats.add({
'game_id': gameId, 'member_id': playerId, 'team_id': isMyTeamPlayer ? myTeamDbId! : oppTeamDbId!,
'pts': stats['pts'], 'rbs': stats['rbs'], 'ast': stats['ast'], 'stl': stats['stl'], 'blk': stats['blk'], 'tov': stats['tov'], 'fls': stats['fls'], 'fgm': stats['fgm'], 'fga': stats['fga'], 'ftm': stats['ftm'], 'fta': stats['fta'], 'orb': stats['orb'], 'drb': stats['drb'],
'p2m': stats['p2m'], 'p2a': stats['p2a'], 'p3m': stats['p3m'], 'p3a': stats['p3a'],
});
}
});