30

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

Ymi_Yugy
  • 513
  • 1
  • 4
  • 7
  • According to the official doc (https://api.flutter.dev/flutter/services/HapticFeedback/lightImpact.html) it should work on Android as well. Did you try one of the other static methods like selectionClick? If it still doesn't work maybe you could provide a code sample where it doesn't work in your case – kounex May 31 '19 at 22:25
  • Here is my answer for both android and ios: https://stackoverflow.com/questions/56413987/how-to-implement-vibration-with-flutter-for-both-android-and-ios/63622425#63622425 – Cassio Seffrin Aug 27 '20 at 19:02

7 Answers7

30

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

Sergey
  • 1,075
  • 14
  • 20
  • 2
    @ChiragChopra please make sure that Vibration feedback is enabled on the device, see this comment - https://github.com/flutter/flutter/issues/33750#issuecomment-499703756 – Sergey Jul 08 '20 at 21:33
12

import 'package:flutter/services.dart';

  1. import the services package

then inside onTap method

onTap: () { Clipboard.setData(ClipboardData(text: data)); HapticFeedback.heavyImpact(); }

it worked for me.

Siva Mani
  • 141
  • 2
  • 6
  • this doesn't work for me, eventually I had to use Vibrate package but I'm wondering why this native implementation doesn't seem to work. – Rishabh Agrawal Dec 29 '21 at 06:14
10

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

iamnabink
  • 454
  • 9
  • 27
6

Try using this for Android:

Feedback.forTap(context);

More info: https://api.flutter.dev/flutter/material/Feedback-class.html

diegoveloper
  • 93,875
  • 20
  • 236
  • 194
5

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

Shailendra Rajput
  • 2,131
  • 17
  • 26
4

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.

Louis Eppler
  • 223
  • 1
  • 8
-3

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)
srt111
  • 1,079
  • 11
  • 20