melhorar os icon de jogo
This commit is contained in:
@@ -89,6 +89,9 @@ class PlacarController extends ChangeNotifier {
|
||||
double arcRadius = 0.459;
|
||||
double cornerY = 0.440;
|
||||
|
||||
// 👇 NOVO: Temporizador para o Auto-Save não travar a App
|
||||
Timer? _autoSaveTimer;
|
||||
|
||||
Future<void> loadPlayers() async {
|
||||
final supabase = Supabase.instance.client;
|
||||
try {
|
||||
@@ -193,7 +196,6 @@ class PlacarController extends ChangeNotifier {
|
||||
"p2m": s['p2m'] ?? 0, "p2a": s['p2a'] ?? 0, "p3m": s['p3m'] ?? 0, "p3a": s['p3a'] ?? 0,
|
||||
"so": s['so'] ?? 0, "il": s['il'] ?? 0, "li": s['li'] ?? 0,
|
||||
"pa": s['pa'] ?? 0, "tres_s": s['tres_seg'] ?? 0, "dr": s['dr'] ?? 0,
|
||||
// 👇 AGORA CARREGA OS SEGUNDOS EXATOS DA BASE DE DADOS
|
||||
"min": (s['minutos_jogados'] ?? 0) ~/ 60,
|
||||
"sec": s['minutos_jogados'] ?? 0,
|
||||
};
|
||||
@@ -226,6 +228,14 @@ class PlacarController extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
// 👇 MÁGICA 1: O "Anti-Spam". Ele acumula as mudanças e só grava 1.5s depois de parares de clicar!
|
||||
void _scheduleAutoSave() {
|
||||
_autoSaveTimer?.cancel();
|
||||
_autoSaveTimer = Timer(const Duration(milliseconds: 1500), () {
|
||||
_saveLocalBackup();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _saveLocalBackup() async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
@@ -277,12 +287,11 @@ class PlacarController extends ChangeNotifier {
|
||||
void toggleTimer(BuildContext context) {
|
||||
if (isRunning) {
|
||||
timer?.cancel();
|
||||
_saveLocalBackup();
|
||||
_scheduleAutoSave();
|
||||
} else {
|
||||
timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (durationNotifier.value.inSeconds > 0) {
|
||||
durationNotifier.value -= const Duration(seconds: 1);
|
||||
|
||||
|
||||
void addTimeToCourt(List<String> court) {
|
||||
for (String id in court) {
|
||||
if (playerStats.containsKey(id)) {
|
||||
@@ -292,11 +301,11 @@ class PlacarController extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addTimeToCourt(myCourt);
|
||||
addTimeToCourt(oppCourt);
|
||||
|
||||
notifyListeners();
|
||||
// Avisa APENAS o relógio (e não a App inteira)
|
||||
durationNotifier.value -= const Duration(seconds: 1);
|
||||
|
||||
} else {
|
||||
timer.cancel();
|
||||
@@ -306,7 +315,7 @@ class PlacarController extends ChangeNotifier {
|
||||
durationNotifier.value = const Duration(minutes: 10);
|
||||
myFouls = 0; opponentFouls = 0;
|
||||
myTimeoutsUsed = 0; opponentTimeoutsUsed = 0;
|
||||
_saveLocalBackup();
|
||||
_scheduleAutoSave();
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
@@ -315,7 +324,6 @@ class PlacarController extends ChangeNotifier {
|
||||
isRunning = !isRunning;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void useTimeout(bool isOpponent) {
|
||||
if (isOpponent) {
|
||||
if (opponentTimeoutsUsed < 3) opponentTimeoutsUsed++;
|
||||
@@ -324,7 +332,7 @@ class PlacarController extends ChangeNotifier {
|
||||
}
|
||||
isRunning = false;
|
||||
timer?.cancel();
|
||||
_saveLocalBackup();
|
||||
_scheduleAutoSave();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -367,7 +375,7 @@ class PlacarController extends ChangeNotifier {
|
||||
oppBench[benchIndex] = courtPlayerId;
|
||||
showOppBench = false;
|
||||
}
|
||||
_saveLocalBackup();
|
||||
_scheduleAutoSave();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -407,7 +415,7 @@ class PlacarController extends ChangeNotifier {
|
||||
commitStat(pendingAction!, pendingPlayerId!);
|
||||
|
||||
isSelectingShotLocation = false; pendingAction = null; pendingPlayerId = null;
|
||||
_saveLocalBackup();
|
||||
_scheduleAutoSave();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -471,7 +479,7 @@ class PlacarController extends ChangeNotifier {
|
||||
String time = "${durationNotifier.value.inMinutes.toString().padLeft(2, '0')}:${durationNotifier.value.inSeconds.remainder(60).toString().padLeft(2, '0')}";
|
||||
playByPlay.insert(0, "P$currentQuarter - $time: $committerName $logText");
|
||||
|
||||
_saveLocalBackup();
|
||||
_scheduleAutoSave();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -555,7 +563,7 @@ class PlacarController extends ChangeNotifier {
|
||||
playByPlay.insert(0, "P$currentQuarter - $time: $name $logText");
|
||||
}
|
||||
|
||||
_saveLocalBackup();
|
||||
_scheduleAutoSave();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -620,9 +628,7 @@ class PlacarController extends ChangeNotifier {
|
||||
'fta': stats['fta'], 'orb': stats['orb'], 'drb': stats['drb'], 'p2m': stats['p2m'], 'p2a': stats['p2a'],
|
||||
'p3m': stats['p3m'], 'p3a': stats['p3a'],
|
||||
'so': stats['so'], 'il': stats['il'], 'li': stats['li'], 'pa': stats['pa'], 'tres_seg': stats['tres_s'],
|
||||
'dr': stats['dr'],
|
||||
// 👇 AQUI GUARDA OS SEGUNDOS EXATOS NA BASE DE DADOS (IMPEDE A PERDA DE TEMPO)
|
||||
'minutos_jogados': stats['sec'],
|
||||
'dr': stats['dr'], 'minutos_jogados': stats['sec'],
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -647,6 +653,7 @@ class PlacarController extends ChangeNotifier {
|
||||
@override
|
||||
void dispose() {
|
||||
timer?.cancel();
|
||||
_autoSaveTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user