Reputation: 633
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
Upvotes: 40
Views: 53346
Reputation: 2877
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
Upvotes: 14
Reputation: 1539
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)
Upvotes: -3
Reputation: 520
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
Upvotes: 14
Reputation: 343
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.
Upvotes: 6
Reputation: 181
import 'package:flutter/services.dart';
then inside onTap method
onTap: () {
Clipboard.setData(ClipboardData(text: data));
HapticFeedback.heavyImpact();
}
it worked for me.
Upvotes: 16
Reputation: 1193
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: https://github.com/flutter/flutter/issues/33750
Upvotes: 35
Reputation: 103421
Try using this for Android:
Feedback.forTap(context);
More info: https://api.flutter.dev/flutter/material/Feedback-class.html
Upvotes: 6