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 working? I am testing with the latest Flutter version 1.6.6 on a Galaxy S8 running Android 9.0

2

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:

1

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.

1

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

1

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.

0

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest