Skip to content
Snippets Groups Projects
Commit 1b21065c authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Add animation on fill cells with color

parent ec486eef
No related branches found
No related tags found
1 merge request!12Resolve "Add a "fill color" animation"
Pipeline #2766 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.9
app.versionCode=9
app.versionName=0.0.10
app.versionCode=10
......@@ -14,17 +14,11 @@ class Cell {
String imageAsset = this.getImageAssetName(myProvider);
return Container(
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 100),
transitionBuilder: (Widget child, Animation<double> animation) {
return ScaleTransition(child: child, scale: animation);
},
child: Image(
image: AssetImage(imageAsset),
fit: BoxFit.fill,
key: ValueKey<int>(imageAsset.hashCode),
),
),
);
}
......
import 'dart:math';
import 'dart:async';
import '../entities/cell.dart';
import '../provider/data.dart';
......@@ -56,9 +57,20 @@ class BoardUtils {
List cellsToFill = BoardUtils.getSiblingFillableCells(myProvider, 0, 0, [[0, 0]]);
int progressBeforeMove = cellsToFill.length;
for (var cellIndex = 0; cellIndex < cellsToFill.length; cellIndex++) {
// Sort cells from the closest to the furthest, relatively to the top left corner
cellsToFill.sort((a, b) => (pow(a[0], 2) + pow(a[1], 2)).compareTo(pow(b[0], 2) + pow(b[1], 2)));
Timer _timerAnimateBoard;
const interval = const Duration(milliseconds: 10);
int cellIndex = 0;
_timerAnimateBoard = new Timer.periodic(
interval,
(Timer timer) {
if (cellIndex < cellsToFill.length) {
myProvider.updateCellValue(cellsToFill[cellIndex][1], cellsToFill[cellIndex][0], value);
}
cellIndex++;
} else {
timer.cancel();
int progressAfterMove = BoardUtils.getSiblingFillableCells(myProvider, 0, 0, [[0, 0]]).length;
int progressDelta = progressAfterMove - progressBeforeMove;
......@@ -67,6 +79,9 @@ class BoardUtils {
myProvider.incrementMovesCount();
}
},
);
}
static List getSiblingFillableCells(Data myProvider, row, col, siblingCells) {
List cells = myProvider.cells;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment