In app development, implementing vibration is a basic yet highly versatile feature that youโll want to implement as one of the first tutorial-like stages. The method for implementing vibration in Flutter app development is kept simpler compared to methods using Java and other languages.
Add the following to pubspec.yaml.
dependencies:
vibration: ^1.7.3
Add the following to AndroidManifest.xml.
<uses-permission android:name="android.permission.VIBRATE"/>
Edit the dart file as follows. With this
import 'package:vibration/vibration.dart';
..
Vibration.vibrate();
Example of vibrating only when vibration functionality is available
if (await Vibration.hasAmplitudeControl()) {
Vibration.vibrate(amplitude: 128);
}
If you want to specify vibration patterns or duration
Vibration.vibrate(duration: 1000);
Vibration.vibrate(pattern: [500, 1000, 500, 2000]);
(Reference)