How to implement vibration with Flutter for both Android and iOS?

I will recommend to use flutter_vibrate, it will work for both ios/ android. Simplier setup and works very well.

  1. Just add flutter_vibrate as a dependency in your pubspec.yaml file.

    dependencies: vibration: ^1.4.0

  2. Make sure you add the following permissions to your Android Manifest

  3. Import the package:

    import 'package:vibration/vibration.dart';

Examples:

Vibrate for default 500ms:

Vibration.vibrate();
       

Vibrate for 1000ms:

Vibration.vibrate(duration: 1000);
           

Pattern: wait 0.5s, vibrate 1s, wait 0.5s, vibrate 2s, wait 0.5s, vibrate 3s, wait 0.5s, vibrate 0.5s:

Vibration.vibrate(pattern: [500, 1000, 500, 2000, 500, 3000, 500, 500]);
            

Pattern: wait 0.5s, vibrate 1s, wait 0.5s, vibrate 2s, wait 0.5s, vibrate 3s, wait 0.5s, vibrate 0.5s':

Vibration.vibrate( pattern: [500, 1000, 500, 2000, 500, 3000, 500, 500], intensities: [128, 255, 64, 255]);

Android

The VIBRATE permission is required in AndroidManifest.xml.

Supports vibration with duration and pattern. On Android 8 (Oreo) and above, uses the [VibrationEffect][1] class. For the rest of the usage instructions, see [Vibrator][1] class documentation.

iOS

Supports vibration with duration and pattern on CoreHaptics devices. On older devices, the pattern is emulated with 500ms long vibrations. You can check whether the current device has CoreHaptics support using hasCustomVibrationsSupport.


Found a way using HapticFeedback.vibrate(). It works for both iOS and Android. See more details with code example and other settings on this [post][1]: Flutter: How to use HapticFeedback


The simplest solution for Flutter 2021

1) Import standard services:

import 'package:flutter/services.dart';

2) Use:

HapticFeedback.mediumImpact();

or lightImpact, or heavyImpact

3) Don't forget to add this at Android Manifest:

<uses-permission android:name="android.permission.VIBRATE"/>

BONUS) Play "Click" Sound:

SystemSound.play(SystemSoundType.click);

First, you need to add vibrate: as a dependency to your pubspec.yaml file.

dependencies:
  flutter:
    sdk: flutter
  vibrate:

After this, you need to import the package in the class that you are using.

// Import package
import 'package:vibrate/vibrate.dart';

Now you can this for vibration:

// Check if the device can vibrate
bool canVibrate = await Vibrate.canVibrate;

// Vibrate
// Vibration duration is a constant 500ms because
// it cannot be set to a specific duration on iOS.
Vibrate.vibrate();

// Vibrate with pauses between each vibration
final Iterable<Duration> pauses = [
    const Duration(milliseconds: 500),
    const Duration(milliseconds: 1000),
    const Duration(milliseconds: 500),
];
// vibrate - sleep 0.5s - vibrate - sleep 1s - vibrate - sleep 0.5s - vibrate
Vibrate.vibrateWithPauses(pauses);

or for haptic feedback:

// Choose from any of these available methods
enum FeedbackType {
  success,
  error,
  warning,
  selection,
  impact,
  heavy,
  medium,
  light
}

var _type = FeedbackType.impact;
Vibrate.feedback(_type);

Source: https://github.com/clovisnicolas/flutter_vibrate