advanced_haptics 1.0.0
advanced_haptics: ^1.0.0 copied to clipboard
A Flutter plugin for playing advanced, custom haptic feedback patterns on Android and iOS, including waveforms and Core Haptics .ahap files.
# Advanced Haptics
A Flutter plugin for playing powerful, custom haptic feedback patterns. This package provides a unified API for Android and iOS, giving developers access to fine-grained vibration control and Apple Core Haptics `.ahap` files.
[](https://pub.dev/packages/advanced_haptics)
[](https://opensource.org/licenses/MIT)
---
## âĻ Features
- â
**Unified API** for Android and iOS
- ðŊ **Custom Waveforms**: Full control of timing and intensity
- ð **Core Haptics on iOS**: Play `.ahap` files for rich tactile feedback
- ð§ **Predefined Patterns**: Built-in methods like `lightTap()`, `successBuzz()`, `error()`, and more
- ðĄïļ **Capability Detection**: Automatically detects device haptics support
- ðŠķ **Fallback Support**: Gracefully degrades on unsupported devices
---
## ðĨ Platform Support
| Feature | Android 8.0+ | iOS 13.0+ (iPhone 8+) |
|-----------------------|--------------|------------------------|
| Waveform | â
Native | â
Emulated |
| `.ahap` Playback | ð Fallback | â
Native |
| Amplitude Control | â
Native | â
Native |
| Predefined Patterns | â
Yes | â
Yes |
> âđïļ **Note:** iPads do not support Core Haptics. Use `hasCustomHapticsSupport()` to verify.
---
## ð Getting Started
### 1. Install
```yaml
dependencies:
advanced_haptics: ^0.0.1
flutter pub get
2. Android Setup #
Add the following permission to android/app/src/main/AndroidManifest.xml
:
<uses-permission android:name="android.permission.VIBRATE"/>
3. iOS Setup #
Add your .ahap
files under assets/haptics/
, and include them in your pubspec.yaml
:
flutter:
assets:
- assets/haptics/
Ensure your target device is an iPhone 8+ running iOS 13+.
ðĻ Example .ahap
File (iOS only) #
{
"Version": 1,
"Pattern": [
{
"Event": {
"Time": 0.0,
"EventType": "HapticTransient",
"EventParameters": [
{ "ParameterID": "HapticIntensity", "ParameterValue": 1.0 },
{ "ParameterID": "HapticSharpness", "ParameterValue": 1.0 }
]
}
}
]
}
Design .ahap
files using Captain AHAP or manually.
ðĶ Usage #
import 'package:advanced_haptics/advanced_haptics.dart';
â Check Support #
if (await AdvancedHaptics.hasCustomHapticsSupport()) {
// Safe to use advanced feedback
}
⥠Predefined Haptic Patterns #
await AdvancedHaptics.lightTap();
await AdvancedHaptics.mediumTap();
await AdvancedHaptics.heavyRumble();
await AdvancedHaptics.successBuzz();
await AdvancedHaptics.selectionClick();
await AdvancedHaptics.error();
await AdvancedHaptics.success();
ð Custom Waveform (Android preferred) #
await AdvancedHaptics.playWaveform(
[0, 100, 150, 100], // timings in ms
[0, 180, 0, 255], // amplitudes 0â255
);
ð Play .ahap
(iOS only) #
await AdvancedHaptics.playAhap('assets/haptics/rumble.ahap');
ð Stop All Vibrations #
await AdvancedHaptics.stop();
ð§ API Reference #
Method | Description |
---|---|
hasCustomHapticsSupport() |
Check platform and hardware support |
playWaveform(timings, amplitudes) |
Custom vibration pattern (Android) |
playAhap(path) |
Play an iOS .ahap haptic file |
stop() |
Stop any ongoing vibration |
success() |
Predefined double-tap haptic |
lightTap({timings, amplitudes}) |
Quick subtle feedback |
mediumTap({timings, amplitudes}) |
Mid-strength feedback |
heavyRumble({timings, amplitudes}) |
Strong feedback |
successBuzz({timings, amplitudes}) |
Buzz-buzz style success pattern |
error({timings, amplitudes}) |
Alert/failure feedback |
selectionClick({timings, amplitudes}) |
Crisp, click-like haptic |
ð Contributing #
Pull requests and issues are welcome! Please test across devices and provide logs if possible.
ð License #
This project is licensed under the MIT License. See LICENSE for full details.