hitTestAll method

  1. @override
List<LuckyHit> hitTestAll(
  1. WheelConfig config,
  2. WheelLayout layout,
  3. WheelFrame frame,
  4. Offset position,
)
override

返回包含 position 的最小半径按钮;边界算命中,无按钮返回空。

Implementation

@override
List<LuckyHit> hitTestAll(WheelConfig config, WheelLayout layout,
    WheelFrame frame, Offset position) {
  final distance = (position - layout.center).distance;
  var index = -1;
  var radius = double.infinity;
  for (var i = 0; i < layout.buttons.length; i++) {
    final current = layout.buttons[i].radius;
    if (current > 0 && distance <= current && current < radius) {
      index = i;
      radius = current;
    }
  }
  return index < 0 ? const [] : [LuckyHit.button(index)];
}