vibration_fixed 4.0.0
vibration_fixed: ^4.0.0 copied to clipboard
A fixed plugin for handling Vibration API on iOS, Android, web and OpenHarmony.
🔥 Vibration Fixed Plugin #
✨ Features #
- 🎯 Cross-platform support - iOS, Android, Web, OpenHarmony
- 🎨 Custom patterns - Support for complex vibration patterns
- 📱 Amplitude control - Control vibration strength (Android)
- 🍎 Haptic feedback - iOS haptic feedback integration
- 🎵 Preset patterns - Pre-defined patterns for common use cases
- 🔍 Device detection - Check device vibration capabilities
- 🛡️ Error handling - Robust error handling and fallbacks
🚀 Installation #
Add to your pubspec.yaml:
dependencies:
vibration_fixed: ^4.0.0
💡 Quick Usage #
import 'package:vibration_fixed/vibration_fixed.dart';
// Basic vibration
await Vibration.vibrate();
// Custom duration
await Vibration.vibrate(duration: 1000);
// Check device support
if (await Vibration.hasVibrator()) {
await Vibration.vibrate();
}
// Use presets
await Vibration.vibrate(preset: VibrationPreset.quickSuccessAlert);
🔧 API Reference #
Methods #
| Method | Description | Returns |
|---|---|---|
hasVibrator() |
Check if device has vibrator | Future<bool> |
hasAmplitudeControl() |
Check amplitude support | Future<bool> |
hasCustomVibrationsSupport() |
Check custom vibration support | Future<bool> |
vibrate({...}) |
Vibrate with parameters | Future<void> |
cancel() |
Cancel ongoing vibration | Future<void> |
Parameters #
| Parameter | Type | Description | Default |
|---|---|---|---|
duration |
int |
Vibration duration (ms) | 500 |
pattern |
List<int> |
Custom pattern array | [] |
repeat |
int |
Pattern repeat count | -1 |
intensities |
List<int> |
Intensity values (iOS) | [] |
amplitude |
int |
Amplitude 1-255 (Android) | -1 |
sharpness |
double |
Sharpness 0.0-1.0 (iOS) | 0.5 |
preset |
VibrationPreset? |
Predefined pattern | null |
📊 Platform Support #
| Platform | Basic | Amplitude | Patterns | Haptic |
|---|---|---|---|---|
| Android | ✅ | ✅ | ✅ | ❌ |
| iOS | ✅ | ❌ | ✅ | ✅ |
| Web | ✅ | ❌ | ❌ | ❌ |
| OpenHarmony | ✅ | ✅ | ✅ | ❌ |
🎨 Examples #
Basic Vibration #
await Vibration.vibrate();
await Vibration.vibrate(duration: 1000);
Custom Patterns #
await Vibration.vibrate(
pattern: [0, 500, 200, 500],
repeat: 1,
);
Preset Patterns #
await Vibration.vibrate(preset: VibrationPreset.quickSuccessAlert);
await Vibration.vibrate(preset: VibrationPreset.lightImpact);
Amplitude Control (Android) #
if (await Vibration.hasAmplitudeControl()) {
await Vibration.vibrate(
duration: 1000,
amplitude: 128,
);
}
🔍 Troubleshooting #
Android #
- Add
VIBRATEpermission toAndroidManifest.xml - Check device support:
await Vibration.hasVibrator()
iOS #
- Haptic feedback only works on physical devices
- Ensure device supports haptic feedback
Web #
- Requires user interaction (button click, etc.)
- Some browsers may not support the API
📄 License #
MIT License - see LICENSE file for details.
Made with ❤️ by Boughdiri Dorsaf