Flutter: How to Use Hapticfeedback
I Have Imported Import 'Package: Flutter/Services. Dart'; and Then Called Hapticfeedback. lightImpact(); Nothing Happens. What Do I Need to Do to Get It...
I have imported
import 'package:flutter/services.dart';
and then called
HapticFeedback.lightImpact();
nothing happens. What do I need to do to get it working? I am testing with the latest Flutter version 1.6.6 on a Galaxy S8 running Android 9.0
7 Answers
Please make sure that Vibration feedback is enabled on the android device, and make sure to add
<uses-permission android:name="android.permission.VIBRATE" />
to the AndroidManifest.xml. See more info here:
import 'package:flutter/services.dart';
- import the services package
then inside onTap method
onTap: () {
Clipboard.setData(ClipboardData(text: data));
HapticFeedback.heavyImpact();
}
it worked for me.
Please also check whether, Vibration feedback setting was enabled on the device or not . I faced same issue but later found out that Haptic Feedback vibration was off on my device (I was testing it in Android 9) so, make sure to enable it.
To enable it,
Go to settings>sound&vibration>touch vibration
This is helped me
First Go to AndroidManifest and add
<uses-permission android:name="android.permission.VIBRATE" />
If the Flutter app is running stop it and run it again. Then use this code
import 'package:flutter/services.dart';
And in Ontap or OnPressed Method
Clipboard.setData(ClipboardData());
HapticFeedback.heavyImpact();
That's all
Try using this for Android:
Feedback.forTap(context);
More info:
Reading the function description it says:
"On Android, this uses HapticFeedbackConstants.KEYBOARD_TAP."
If the vibrations for the keyboard or 'haptic feedback for tap' are turned off (in the phone's settings), calling HapticFeedback.mediumImpact(); will not have an effect.
To fix the problem one would have to turn on Touch vibration in the phone's settings.
If only activating touch vibration on phone doesn't solve the issue , try switching between Vibrate on tap modes.Default setting is Off.
Vibrate on tap (Settings -Off(default),Ligh,Medium,Strong)