@@ -14,6 +14,7 @@ import 'dart:ui' show ImageFilter, lerpDouble;
1414import 'package:flutter/foundation.dart' ;
1515import 'package:flutter/gestures.dart' ;
1616import 'package:flutter/rendering.dart' ;
17+ import 'package:flutter/services.dart' ;
1718import 'package:flutter/widgets.dart' ;
1819
1920import 'colors.dart' ;
@@ -595,7 +596,10 @@ abstract class _ActionSheetSlideTarget {
595596 // * The point has contacted the screen in this region. In this case, this
596597 // method is called as soon as the pointer down event occurs regardless of
597598 // whether the gesture wins the arena immediately.
598- void didEnter ();
599+ //
600+ // The `fromPointerDown` should be true if this callback is triggered by a
601+ // PointerDownEvent, i.e. the second case from the list above.
602+ void didEnter ({required bool fromPointerDown});
599603
600604 // A pointer has exited this region.
601605 //
@@ -660,7 +664,10 @@ class _TargetSelectionGestureRecognizer extends GestureRecognizer {
660664 // Collect the `_ActionSheetSlideTarget`s that are currently hit by the
661665 // pointer, check whether the current target have changed, and invoke their
662666 // methods if necessary.
663- void _updateDrag (Offset pointerPosition) {
667+ //
668+ // The `fromPointerDown` should be true if this update is triggered by a
669+ // PointerDownEvent.
670+ void _updateDrag (Offset pointerPosition, {required bool fromPointerDown}) {
664671 final HitTestResult result = hitTest (pointerPosition);
665672
666673 // A slide target might nest other targets, therefore multiple targets might
@@ -686,21 +693,21 @@ class _TargetSelectionGestureRecognizer extends GestureRecognizer {
686693 ..clear ()
687694 ..addAll (foundTargets);
688695 for (final _ActionSheetSlideTarget target in _currentTargets) {
689- target.didEnter ();
696+ target.didEnter (fromPointerDown : fromPointerDown );
690697 }
691698 }
692699 }
693700
694701 void _onDown (DragDownDetails details) {
695- _updateDrag (details.globalPosition);
702+ _updateDrag (details.globalPosition, fromPointerDown : true );
696703 }
697704
698705 void _onUpdate (Offset globalPosition) {
699- _updateDrag (globalPosition);
706+ _updateDrag (globalPosition, fromPointerDown : false );
700707 }
701708
702709 void _onEnd (Offset globalPosition) {
703- _updateDrag (globalPosition);
710+ _updateDrag (globalPosition, fromPointerDown : false );
704711 for (final _ActionSheetSlideTarget target in _currentTargets) {
705712 target.didConfirm ();
706713 }
@@ -1121,7 +1128,7 @@ class _CupertinoActionSheetActionState extends State<CupertinoActionSheetAction>
11211128 implements _ActionSheetSlideTarget {
11221129 // |_ActionSheetSlideTarget|
11231130 @override
1124- void didEnter () {}
1131+ void didEnter ({ required bool fromPointerDown} ) {}
11251132
11261133 // |_ActionSheetSlideTarget|
11271134 @override
@@ -1243,11 +1250,27 @@ class _ActionSheetButtonBackground extends StatefulWidget {
12431250class _ActionSheetButtonBackgroundState extends State <_ActionSheetButtonBackground > implements _ActionSheetSlideTarget {
12441251 bool isBeingPressed = false ;
12451252
1253+ void _emitVibration (){
1254+ switch (defaultTargetPlatform) {
1255+ case TargetPlatform .iOS:
1256+ case TargetPlatform .android:
1257+ HapticFeedback .selectionClick ();
1258+ case TargetPlatform .fuchsia:
1259+ case TargetPlatform .linux:
1260+ case TargetPlatform .macOS:
1261+ case TargetPlatform .windows:
1262+ break ;
1263+ }
1264+ }
1265+
12461266 // |_ActionSheetSlideTarget|
12471267 @override
1248- void didEnter () {
1268+ void didEnter ({ required bool fromPointerDown} ) {
12491269 setState (() { isBeingPressed = true ; });
12501270 widget.onPressStateChange? .call (true );
1271+ if (! fromPointerDown) {
1272+ _emitVibration ();
1273+ }
12511274 }
12521275
12531276 // |_ActionSheetSlideTarget|
0 commit comments