Ymi_Yugy
Ymi_Yugy

Reputation: 633

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

Upvotes: 40

Views: 53346

Answers (7)

Shailendra Rajput
Shailendra Rajput

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

srt111
srt111

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

iamnabink
iamnabink

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

Louis Eppler
Louis Eppler

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

Siva Mani
Siva Mani

Reputation: 181

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.

Upvotes: 16

Sergey
Sergey

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

diegoveloper
diegoveloper

Reputation: 103421

Try using this for Android:

Feedback.forTap(context);

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

Upvotes: 6

Related Questions