Skip to content

đź“ł Using haptic feedback to make your Flutter app more interactive

 at 

What is haptic feedback?

Haptic feedback makes your app more interactive and engaging. They provide users with a response when they interact with your app, which can help to create a more expressive experience. In this article, we’ll take a look at how you can use haptic feedback in your Flutter app, and when to use which type of feedback.

”Playing haptics can engage people’s sense of touch and bring their familiarity with the physical world into your app or game.” - Apple Docs

How to use haptic feedback in Flutter?

Flutter provides a HapticFeedback class that you can use to trigger haptic feedback in your app.

However, the options that it provides is limited and might need extra mixture to have haptic for different interactions such as success, error, warning, etc.

For this reason, you can use the haptic_feedback package, which provides a more comprehensive set of haptic feedback that you can use in your app.

Here’s an example of how you can use the haptic_feedback package to trigger a haptic feedback when a button is pressed:

await Haptics.vibrate(HapticsType.success);

To be sure before calling to vibrate method, you can check if the device supports haptic feedback:

if (await Haptics.canVibrate()) {
  await Haptics.vibrate(HapticsType.success);
}

I personally call the vibrate method in a separate class to make it more reusable and clean:

import 'package:haptic_feedback/haptic_feedback.dart';

class HapticsHelper {
  HapticsHelper._();

  static bool? _canVibrate;

  static Future<void> vibrate(HapticsType hapticsType) async {
    _canVibrate ??= await Haptics.canVibrate();

    if (_canVibrate ?? false) {
      await Haptics.vibrate(hapticsType);
    }
  }
}

And then call it like this:

await HapticsHelper.vibrate(HapticsType.success);

When to use which haptic feedback?

When using haptic feedback in your app, it’s important to choose the right type for the interaction.

”It’s important to build a clear, causal relationship between each haptic and the action that causes it so people learn to associate certain haptic patterns with certain experiences.”

Here are some examples of when to use which haptic feedback:

HapticsType.success: Indicates that a task or action has completed. Example cases:

HapticsType.warning: Indicates that a task or action has produced a warning of some kind. Example cases:

HapticsType.error: Indicates that an error has occurred. Example cases:

HapticsType.light: Indicates a collision between small or lightweight UI objects. Example cases:

HapticsType.medium: Indicates a collision between medium-sized or medium-weight UI objects. Example cases:

HapticsType.heavy: Indicates a collision between large or heavyweight UI objects. Example cases:

HapticsType.rigid: Indicates a collision between hard or inflexible UI objects. Example cases:

HapticsType.soft: Indicates a collision between soft or flexible UI objects. Example cases:

HapticsType.selection: Indicates that a UI element’s values are changing. Example cases:

”A haptic can feel just right when it happens occasionally, but become tiresome when it plays frequently. Often, the best haptic experience is one that people may not be conscious of, but miss when it’s turned off”

Further reading:



Subscribe to the newsletter
Kamran Bekirov

I'm Kamran Bekirov
Built over 70 mobile apps.
Building UserOrient for Flutter
Solo apps: LibroKit, Beyt
Packages: logarte, versionarte
Reach: X, LinkedIn, Instagram, GitHub