@@ -26,7 +26,7 @@ typedef IndicatorAppearingBuilder = Widget Function(
2626
2727typedef ChangeCallback <T > = FutureOr <void > Function (T value);
2828
29- typedef TapCallback <T > = FutureOr <void > Function (TapInfo <T > info );
29+ typedef TapCallback <T > = FutureOr <void > Function (TapProperties <T > props );
3030
3131enum ToggleMode { animating, dragged, none }
3232
@@ -357,7 +357,7 @@ class _CustomAnimatedToggleSwitchState<T>
357357
358358 /// This method is called in two [GestureDetector] s because only one
359359 /// [GestureDetector.onTapUp] will be triggered.
360- void _onTap (TapInfo <T > info) {
360+ void _onTap (TapProperties <T > info) {
361361 if (! _isActive) return ;
362362 final result = widget.onTap? .call (info);
363363 if (result is Future ) {
@@ -377,8 +377,8 @@ class _CustomAnimatedToggleSwitchState<T>
377377 /// IMPORTANT: This must be called in [didUpdateWidget] because it updates
378378 /// [_currentIndex] also.
379379 void _checkValuePosition () {
380- if (_animationInfo.toggleMode == ToggleMode .dragged) return ;
381380 _currentIndex = widget.values.indexOf (widget.current);
381+ if (_animationInfo.toggleMode == ToggleMode .dragged) return ;
382382 if (_currentIndex >= 0 ) {
383383 _animateTo (_currentIndex);
384384 } else {
@@ -402,11 +402,17 @@ class _CustomAnimatedToggleSwitchState<T>
402402 return result;
403403 }
404404
405- /// Returns the value index by the local position of the cursor.
405+ /// Returns the [TapInfo] by the local position of the cursor.
406406 /// It is mainly intended as a helper function for the build method.
407- int _indexFromPosition (
407+ TapInfo < T > _tapInfoFromPosition (
408408 double x, DetailedGlobalToggleProperties <T > properties) {
409- return _doubleFromPosition (x, properties).round ();
409+ final position = _doubleFromPosition (x, properties);
410+ final index = position.round ();
411+ return TapInfo (
412+ value: widget.values[index],
413+ index: index,
414+ position: position,
415+ );
410416 }
411417
412418 @override
@@ -433,11 +439,8 @@ class _CustomAnimatedToggleSwitchState<T>
433439 cursor: defaultCursor,
434440 child: GestureDetector (
435441 behavior: HitTestBehavior .deferToChild,
436- onTapUp: (_) => _onTap (TapInfo (
437- tappedIndex: - 1 ,
438- tappedValue: null ,
439- current: widget.current,
440- currentIndex: _currentIndex,
442+ onTapUp: (_) => _onTap (TapProperties (
443+ tapped: null ,
441444 values: widget.values,
442445 )),
443446 child: TweenAnimationBuilder <double >(
@@ -648,20 +651,17 @@ class _CustomAnimatedToggleSwitchState<T>
648651 behavior: HitTestBehavior .translucent,
649652 dragStartBehavior: DragStartBehavior .down,
650653 onTapUp: (details) {
651- int tappedIndex = _indexFromPosition (
654+ final tapInfo = _tapInfoFromPosition (
652655 details.localPosition.dx, properties);
653- T tappedValue =
654- widget.values[tappedIndex];
655- _onTap (TapInfo (
656- tappedIndex: tappedIndex,
657- tappedValue: tappedValue,
658- current: widget.current,
659- currentIndex: _currentIndex,
656+ _onTap (TapProperties (
657+ tapped: tapInfo,
660658 values: widget.values,
661659 ));
662660 if (! widget.iconsTappable) return ;
663- if (tappedValue == widget.current) return ;
664- _onChanged (tappedValue);
661+ if (tapInfo.value == widget.current) {
662+ return ;
663+ }
664+ _onChanged (tapInfo.value);
665665 },
666666 onHorizontalDragStart: (details) {
667667 if (! isHoveringIndicator (
0 commit comments