vibrate static method

Future<void> vibrate(
  1. HapticsType type, {
  2. HapticsUsage? usage,
  3. bool useAndroidHapticConstants = false,
})

Performs haptic feedback of HapticsType on the device. Performs nothing if the platform is not supported.

Provide usage to influence how Android routes the vibration when running on API level 33 or later (for example, HapticsUsage.media for breathing exercises). The value is ignored on older Android versions and on iOS.

On Android, set useAndroidHapticConstants to true to use the platform HapticFeedbackConstants (e.g., CONFIRM, REJECT, VIRTUAL_KEY) when available. Set to false to use custom vibration primitives instead, which more closely mirror the iOS patterns. Native constants respect Android's touch-feedback settings and ignore usage. Custom patterns are used if no mapped constant or activity is available; a dispatched constant never falls back because it was muted.

Implementation

static Future<void> vibrate(
  HapticsType type, {
  HapticsUsage? usage,
  bool useAndroidHapticConstants = false,
}) async {
  if (!isPlatformSupported) {
    return;
  }

  return HapticFeedbackPlatform.instance.vibrate(
    type,
    usage: usage,
    useAndroidHapticConstants: useAndroidHapticConstants,
  );
}