bora para o relatorio

This commit is contained in:
2026-05-21 10:51:35 +01:00
parent 332361c296
commit 7d2f3c4679
3 changed files with 435 additions and 293 deletions

View File

@@ -139,6 +139,36 @@ class PlacarController extends ChangeNotifier {
_setTimerRunning(shouldRun, emitSync: false);
}
void applyRemoteAddShot(Map<String, dynamic> shotJson) {
try {
matchShots.add(ShotRecord.fromJson(shotJson));
notifyListeners();
} catch (e) {
debugPrint('Erro ao aplicar shot remoto: $e');
}
}
Future<void> _persistShotRemote(Map<String, dynamic> shotJson) async {
try {
final supabase = Supabase.instance.client;
final row = {
'game_id': gameId,
'member_id': shotJson['playerId'] ?? shotJson['player_id'],
'player_name': shotJson['playerName'] ?? shotJson['player_name'],
'relative_x': shotJson['relativeX'] ?? shotJson['relative_x'],
'relative_y': shotJson['relativeY'] ?? shotJson['relative_y'],
'is_make': shotJson['isMake'] ?? shotJson['is_make'],
'zone': shotJson['zone'],
'points': shotJson['points'],
};
await supabase.from('shot_locations').insert(row);
debugPrint('✅ Shot persisted remotely');
} catch (e) {
debugPrint('❌ Erro ao persistir shot remoto: $e');
}
}
bool isLoading = true;
bool isSaving = false;
bool gameWasAlreadyFinished = false;
@@ -666,6 +696,14 @@ class PlacarController extends ChangeNotifier {
String finalAction = isMake ? "add_pts_$points" : "miss_$points";
commitStat(finalAction, targetPlayer);
// Emitir evento de shot para parceiros remotos
try {
final shotJson = matchShots.last.toJson();
_dispatchSyncAction('add_shot', {'shot': shotJson});
// Persist shot immediately on server (fire-and-forget)
_persistShotRemote(shotJson);
} catch (_) {}
notifyListeners();
}
@@ -697,6 +735,14 @@ class PlacarController extends ChangeNotifier {
),
);
// Emitir evento de shot para parceiros remotos
try {
final shotJson = matchShots.last.toJson();
_dispatchSyncAction('add_shot', {'shot': shotJson});
// Persist shot immediately on server (fire-and-forget)
_persistShotRemote(shotJson);
} catch (_) {}
commitStat(pendingAction!, pendingPlayerId!);
isSelectingShotLocation = false;