hitTestDots method
Returns the index of the section that contains dx
.
Sections or hit-targets are calculated differently in some effects
Implementation
@override
int hitTestDots(double dx, int count, double current) {
final switchPoint = (maxVisibleDots / 2).floor();
if (fixedCenter) {
return super.hitTestDots(dx, count, current) -
switchPoint +
current.floor();
} else {
final firstVisibleDot =
(current < switchPoint || count - 1 < maxVisibleDots)
? 0
: min(current - switchPoint, count - maxVisibleDots).floor();
final lastVisibleDot =
min(firstVisibleDot + maxVisibleDots, count - 1).floor();
var offset = 0.0;
for (var index = firstVisibleDot; index <= lastVisibleDot; index++) {
if (dx <= (offset += dotWidth + spacing)) {
return index;
}
}
}
return -1;
}