Using Flutter I am trying to implement vibration on a button click.
I find it surprisingly difficult to be honest. I\'ve tried using the following packages unsuccessfully
I will recommend to use flutter_vibrate, it will work for both ios/ android. Simplier setup and works very well.
Just add flutter_vibrate as a dependency in your pubspec.yaml file.
dependencies: vibration: ^1.4.0
Make sure you add the following permissions to your Android Manifest
Import the package:
import 'package:vibration/vibration.dart';
Examples:
Vibrate for default 500ms:
Vibration.vibrate();
Vibrate for 1000ms:
Vibration.vibrate(duration: 1000);
Pattern: wait 0.5s, vibrate 1s, wait 0.5s, vibrate 2s, wait 0.5s, vibrate 3s, wait 0.5s, vibrate 0.5s:
Vibration.vibrate(pattern: [500, 1000, 500, 2000, 500, 3000, 500, 500]);
Pattern: wait 0.5s, vibrate 1s, wait 0.5s, vibrate 2s, wait 0.5s, vibrate 3s, wait 0.5s, vibrate 0.5s':
Vibration.vibrate( pattern: [500, 1000, 500, 2000, 500, 3000, 500, 500], intensities: [128, 255, 64, 255]);
Android
The VIBRATE permission is required in AndroidManifest.xml.
Supports vibration with duration and pattern. On Android 8 (Oreo) and above, uses the [VibrationEffect][1] class. For the rest of the usage instructions, see [Vibrator][1] class documentation.iOS
Supports vibration with duration and pattern on CoreHaptics devices. On older devices, the pattern is emulated with 500ms long vibrations. You can check whether the current device has CoreHaptics support using hasCustomVibrationsSupport.