forLongPress static method

Future<void> forLongPress(
  1. BuildContext context
)

Provides platform-specific feedback for a long press.

On Android the platform-typical vibration is triggered. On iOS a heavy-impact haptic feedback is triggered alongside the click system sound, which was observed to be the default behavior on a physical iPhone 15 Pro running iOS version 17.5.

See also:

Implementation

static Future<void> forLongPress(BuildContext context) {
  context.findRenderObject()!.sendSemanticsEvent(const LongPressSemanticsEvent());
  switch (defaultTargetPlatform) {
    case TargetPlatform.android:
    case TargetPlatform.fuchsia:
      return HapticFeedback.vibrate();
    case TargetPlatform.iOS:
      return Future.wait(<Future<void>>[
        SystemSound.play(SystemSoundType.click),
        HapticFeedback.heavyImpact()
      ]);
    case TargetPlatform.linux:
    case TargetPlatform.macOS:
    case TargetPlatform.windows:
      return Future<void>.value();
  }
}