Flutter Haptic Feedback On Long Press
2,385
You can use vibrate
plugin for that.
Add this dependency in your pubspec.yaml
file
vibrate: ^0.0.4
Use this function in your class for vibration
void vibrate() async {
bool canVibrate = await Vibrate.canVibrate;
canVibrate ? Vibrate.feedback(FeedbackType.medium) : null;
}
And call the above function from your widget when the onLongPress event is triggred
onLongPress: () {
vibrate();
},
More about vibrate plugin.
Hope it helps.
Author by
Admin
Updated on December 08, 2022Comments
-
Admin over 1 year
How are we supposed to cause haptic feedback on long press using Flutter HapticFeedback class?
I am currently working with
HapticFeedback.selectionClick()
during my OnTapDown method, but nothing is happening.I have also already added the vibrate permission in the android manifest file. I am using a Pixel2 XL device for testing.
-
Bisclavret almost 5 years(vibration) is not recognised.
-
Niraj Niroula almost 5 years@Bisclavret Remove the
if
condition, it should work, think it was mistakenly pasted from my project. See the edit.