diff --git a/lib/pangea/pages/games/story_game/round_model.dart b/lib/pangea/pages/games/story_game/round_model.dart index ee54123f0..7c2f16873 100644 --- a/lib/pangea/pages/games/story_game/round_model.dart +++ b/lib/pangea/pages/games/story_game/round_model.dart @@ -67,13 +67,14 @@ class GameRoundModel { controller.roundTimerStateKey.currentState?.resetTimer( roundLength: timerMaxSeconds, ); + controller.roundTimerStateKey.currentState?.startTimer(); } void endRound() { debugPrint("ending round, message IDs: $messageIDs"); endTime = DateTime.now(); state = RoundState.completed; - controller.roundTimerStateKey.currentState?.stopTimeout(); + controller.roundTimerStateKey.currentState?.resetTimer(); syncSubscription?.cancel(); roundCompleter.complete(); } diff --git a/lib/pangea/widgets/chat/round_timer.dart b/lib/pangea/widgets/chat/round_timer.dart index 373fee949..2ea43761f 100644 --- a/lib/pangea/widgets/chat/round_timer.dart +++ b/lib/pangea/widgets/chat/round_timer.dart @@ -8,7 +8,7 @@ class RoundTimer extends StatefulWidget { final int timerMaxSeconds; final Duration roundDuration; - RoundTimer({ + const RoundTimer({ super.key, this.timerMaxSeconds = 180, this.roundDuration = const Duration(seconds: 1), @@ -28,6 +28,7 @@ class RoundTimerState extends State { void resetTimer({Duration? roundDuration, int? roundLength}) { if (_timer != null) { _timer!.cancel(); + isTiming = false; } if (roundDuration != null) { duration = roundDuration; @@ -35,8 +36,9 @@ class RoundTimerState extends State { if (roundLength != null) { timerMaxSeconds = roundLength; } - currentSeconds = 0; - startTimeout(); + setState(() { + currentSeconds = 0; + }); } int get remainingTime => timerMaxSeconds - currentSeconds; @@ -44,7 +46,7 @@ class RoundTimerState extends State { String get timerText => '${(remainingTime ~/ 60).toString().padLeft(2, '0')}: ${(remainingTime % 60).toString().padLeft(2, '0')}'; - startTimeout() { + startTimer() { _timer = Timer.periodic(duration ?? widget.roundDuration, (timer) { setState(() { currentSeconds++; @@ -56,7 +58,7 @@ class RoundTimerState extends State { }); } - stopTimeout() { + stopTimer() { if (_timer != null) { _timer!.cancel(); } @@ -69,7 +71,6 @@ class RoundTimerState extends State { void initState() { duration = widget.roundDuration; timerMaxSeconds = widget.timerMaxSeconds; - startTimeout(); super.initState(); }