From b73d6e37b80ac98152fea7262c2425a591547cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Thu, 16 Jun 2022 08:59:19 +0200 Subject: [PATCH] Disable buttons while fill animation is in progress --- android/gradle.properties | 4 ++-- lib/entities/cell.dart | 4 +++- lib/provider/data.dart | 7 +++++++ lib/utils/board_utils.dart | 2 ++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/android/gradle.properties b/android/gradle.properties index 81949df..957c40b 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true -app.versionName=0.0.14 -app.versionCode=14 +app.versionName=0.0.15 +app.versionCode=15 diff --git a/lib/entities/cell.dart b/lib/entities/cell.dart index 75c4482..db64fe3 100644 --- a/lib/entities/cell.dart +++ b/lib/entities/cell.dart @@ -39,7 +39,9 @@ class Cell { fit: BoxFit.fill ), onTap: () { - BoardUtils.fillBoardFromFirstCell(myProvider, this.value); + if (!myProvider.animationInProgress) { + BoardUtils.fillBoardFromFirstCell(myProvider, this.value); + } }, ) ); diff --git a/lib/provider/data.dart b/lib/provider/data.dart index 2417899..fcb9770 100644 --- a/lib/provider/data.dart +++ b/lib/provider/data.dart @@ -32,6 +32,7 @@ class Data extends ChangeNotifier { // Game data bool _gameIsRunning = false; + bool _animationInProgress = false; bool _gameWon = false; int _boardSize = 0; int _colorsCount = 0; @@ -224,6 +225,12 @@ class Data extends ChangeNotifier { notifyListeners(); } + bool get animationInProgress => _animationInProgress; + void updateAnimationInProgress(bool animationInProgress) { + _animationInProgress = animationInProgress; + notifyListeners(); + } + void resetGame() { _gameIsRunning = false; _gameWon = false; diff --git a/lib/utils/board_utils.dart b/lib/utils/board_utils.dart index 029cbed..b91858c 100644 --- a/lib/utils/board_utils.dart +++ b/lib/utils/board_utils.dart @@ -66,6 +66,7 @@ class BoardUtils { Timer _timerAnimateBoard; const interval = const Duration(milliseconds: 10); int cellIndex = 0; + myProvider.updateAnimationInProgress(true); _timerAnimateBoard = new Timer.periodic( interval, (Timer timer) { @@ -81,6 +82,7 @@ class BoardUtils { myProvider.updateProgress(progressAfterMove); myProvider.incrementMovesCount(); + myProvider.updateAnimationInProgress(false); if (BoardUtils.checkBoardIsSolved(myProvider)) { myProvider.updateGameWon(true); -- GitLab