shimmerHighlightRect function
Rect
shimmerHighlightRect({
- required Size size,
- required ShimmerDirection direction,
- required double percent,
Sliding rectangle used as the shader bounds for the highlight.
The band is three times the child's width or height so the highlight can
travel fully across the child while percent goes from 0.0 to 1.0.
Implementation
@visibleForTesting
Rect shimmerHighlightRect({
required Size size,
required ShimmerDirection direction,
required double percent,
}) {
final double width = size.width;
final double height = size.height;
switch (direction) {
case ShimmerDirection.rtl:
final double dx = _offset(width, -width, percent);
return Rect.fromLTWH(dx - width, 0.0, 3 * width, height);
case ShimmerDirection.ttb:
final double dy = _offset(-height, height, percent);
return Rect.fromLTWH(0.0, dy - height, width, 3 * height);
case ShimmerDirection.btt:
final double dy = _offset(height, -height, percent);
return Rect.fromLTWH(0.0, dy - height, width, 3 * height);
case ShimmerDirection.ltr:
final double dx = _offset(-width, width, percent);
return Rect.fromLTWH(dx - width, 0.0, 3 * width, height);
}
}