Skip to content

Commit

Permalink
Prevent negative countdowns when resuming from InitialLoad or Waiting…
Browse files Browse the repository at this point in the history
… states
  • Loading branch information
dillonfagan committed Feb 8, 2024
1 parent a89a079 commit a2796e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/providers/mob_controller_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class MobController {
}

void resume() {
if (ref.read(mobStateProvider) == MobState.initialLoad) {
return;
}

ref.read(timerProvider.notifier).state = getTimer(ref, () {
_alarm.play();
endTurn();
Expand Down
7 changes: 4 additions & 3 deletions lib/providers/timer_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ Timer getTimer(Ref ref, Function() onStop) {
return Timer.periodic(
const Duration(seconds: 1),
(timer) {
ref.read(secondsProvider.notifier).state -= 1;

if (ref.read(secondsProvider) == 0) {
if (ref.read(secondsProvider) <= 0) {
onStop();
return;
}

ref.read(secondsProvider.notifier).state -= 1;
},
);
}

0 comments on commit a2796e5

Please sign in to comment.