From 57711f540729292c775c1cd4c1ebfe52fda7dc9d Mon Sep 17 00:00:00 2001 From: alestiago Date: Tue, 12 Mar 2024 15:16:55 +0000 Subject: [PATCH] fix: reduce tutorial status builds --- .../lib/src/game/widgets/tutorial_hud.dart | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/trashy_road/lib/src/game/widgets/tutorial_hud.dart b/packages/trashy_road/lib/src/game/widgets/tutorial_hud.dart index 3586688b..e41d8da7 100644 --- a/packages/trashy_road/lib/src/game/widgets/tutorial_hud.dart +++ b/packages/trashy_road/lib/src/game/widgets/tutorial_hud.dart @@ -15,7 +15,7 @@ enum _TutorialStatus { trashDeposit, /// The tutorial has been completed. - completed, + completed; } /// {@template TutorialHud} @@ -30,7 +30,7 @@ class TutorialHud extends StatefulWidget { } class _TutorialHudState extends State { - _TutorialStatus _tutorialStatus = _TutorialStatus.movement; + var _tutorialStatus = _TutorialStatus.movement; @override Widget build(BuildContext context) { @@ -45,19 +45,25 @@ class _TutorialHudState extends State { final hasDepositedTrash = previous.collectedTrash < current.collectedTrash; + late final _TutorialStatus newTutorialStatus; if (_tutorialStatus == _TutorialStatus.movement && hasMoved) { - _tutorialStatus = _TutorialStatus.trashCollection; + newTutorialStatus = _TutorialStatus.trashCollection; } else if (_tutorialStatus == _TutorialStatus.trashCollection && hasCollectedTrash) { - _tutorialStatus = _TutorialStatus.trashDeposit; + newTutorialStatus = _TutorialStatus.trashDeposit; } else if (_tutorialStatus == _TutorialStatus.trashDeposit && hasDepositedTrash) { - _tutorialStatus = _TutorialStatus.completed; + newTutorialStatus = _TutorialStatus.completed; } else { - return false; + newTutorialStatus = _TutorialStatus.completed; } - return true; + final hasChangedStatus = newTutorialStatus != _tutorialStatus; + if (hasChangedStatus) { + _tutorialStatus = newTutorialStatus; + } + + return hasChangedStatus; }, builder: (context, state) { switch (_tutorialStatus) {