draw method
override
Implementation
@override
void draw({
Canvas canvas,
ui.Image paintImage,
double progress,
Offset startingOffset,
}) {
Paint paint = Paint();
Size imageSize =
Size(paintImage.width.toDouble(), paintImage.height.toDouble());
if (_startingOffset != startingOffset) {
calculateStartingCoordinate(
size: imageSize,
startingOffset: startingOffset,
);
_startingOffset = startingOffset;
}
double maxDistance = startingCoordinate.maxDistance(
maxX: numberOfRow - 1,
maxY: numberOfColumn - 1,
);
for (int i = 0; i < numberOfColumn; i++) {
for (int j = 0; j < numberOfRow; j++) {
double currentProgress = calculateFragmentProgress(
maxDistance: maxDistance,
currentCoordinate: Coordinate(x: j, y: i),
);
if (currentProgress > progress) {
Rect rect = calculateFragment(i: i, j: j, size: imageSize);
if (disableTransition == false) {
double opacity = 1;
double transition =
(numberOfRow + numberOfColumn) / (numberOfRow * numberOfColumn);
transition = min(transition, .1);
if (currentProgress - transition < progress) {
opacity = .6;
} else if (currentProgress - transition / 2 < progress) {
opacity = .8;
}
paint.color = Colors.white.withOpacity(opacity);
}
canvas.drawImageRect(paintImage, rect, rect, paint);
}
}
}
}