vibration_composition
A plugin exposing Android's VibrationEffect.Composition API for rich, composable haptics.
- Compose vibration patterns from named primitives (click, tick, thud, spin, ...).
- Per-primitive
scaleanddelay. - Query device capabilities before playing.
Platforms:
- Android: forwards directly to the native composition API.
- iOS: emulated on top of Core Haptics, exposed through the same API.
Usage
See example/lib/main.dart for a full example.
Check support and prepare the vibrator:
import 'package:vibration_composition/vibration_composition.dart' as vib;
final supported = await vib.isCompositionSupported();
final available = await vib.supportedPrimitives();
await vib.prepareVibrator();
Play a composed pattern:
await vib.composeAndPlay([
vib.CompositionParams(primitive: vib.Primitive.click),
vib.CompositionParams(
primitive: vib.Primitive.tick,
scale: 0.6,
delayMs: 100,
delayType: vib.DelayType.afterEndOfPrev,
),
]);
API
isCompositionSupported()- whether the device supports composition.supportedPrimitives()- set ofPrimitives the device can play.primitiveDurations()- map ofPrimitiveto duration in ms.composeAndPlay(pattern)- play a list ofCompositionParams.patternTargetDuration(pattern)- computedDurationof the pattern.envelopeCapability()- envelope effect capabilities, ornull.prepareVibrator()- warm up the vibrator.
CompositionParams
primitive- whichPrimitiveto play.scale- intensity, 0.0 - 1.0 (default1.0).delayMs- delay before this step (default0).delayType-afterEndOfPrev(default) orafterStartOfPrev.