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 scale and delay.
  • 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 of Primitives the device can play.
  • primitiveDurations() - map of Primitive to duration in ms.
  • composeAndPlay(pattern) - play a list of CompositionParams.
  • patternTargetDuration(pattern) - computed Duration of the pattern.
  • envelopeCapability() - envelope effect capabilities, or null.
  • prepareVibrator() - warm up the vibrator.

CompositionParams

  • primitive - which Primitive to play.
  • scale - intensity, 0.0 - 1.0 (default 1.0).
  • delayMs - delay before this step (default 0).
  • delayType - afterEndOfPrev (default) or afterStartOfPrev.