dvIosHapticSoundId function
The system sound identifier that produces a given haptic.
UIImpactFeedbackGenerator is the documented API and is unusable here: it
must be constructed and called on the main thread, and Flutter's root
isolate runs on the UI thread. AudioServicesPlaySystemSound is a plain C
function in AudioToolbox, safe to call from any thread, and the identifiers
in the 1519-1521 range are the Taptic Engine taps rather than sounds.
Throws for a name this does not cover. A fallback would be worse than an error: identifiers below 1000 are alert sounds, so a mistyped name would play a noise out loud on a device meant to tap silently.
Implementation
int dvIosHapticSoundId(String name) => switch (name) {
// Peek: the lightest tap the Taptic Engine produces.
'haptics.lightVibrate' => 1519,
// Pop: firmer, the one that reads as an impact.
'haptics.impact' => 1520,
// kSystemSoundID_Vibrate. The taps above are silent on a device with a
// Taptic Engine and do nothing at all on one without, so a full vibrate
// has to be the real motor.
'haptics.vibrate' => 4095,
_ => throw ArgumentError.value(
name, 'name', 'Not an iOS haptic binding'),
};