hitTestDots method

  1. @override
int hitTestDots(
  1. double dx,
  2. int count,
  3. double current
)
override

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) {
  var anchor = -spacing / 2;
  for (var index = 0; index < count; index++) {
    var dotWidth = dotDecoration.width + dotDecoration.dotBorder.neededSpace;
    if (index == current) {
      dotWidth = activeDotDecoration.width +
          activeDotDecoration.dotBorder.neededSpace;
    }

    var widthBound = dotWidth + spacing;
    if (dx <= (anchor += widthBound)) {
      return index;
    }
  }
  return -1;
}