Skip to content

Instantly share code, notes, and snippets.

@avuenja
Created July 24, 2020 00:01
Show Gist options
  • Save avuenja/db8ba15f48a21e6fce70ab4d0816e3e1 to your computer and use it in GitHub Desktop.
Save avuenja/db8ba15f48a21e6fce70ab4d0816e3e1 to your computer and use it in GitHub Desktop.
Flutter: Haptic Feedback
import 'package:flutter/services.dart';
class HapticFeedback {
static Future<void> lightImpact() async {
await SystemChannels.platform.invokeMethod<void>(
'HapticFeedback.vibrate',
'HapticFeedbackType.lightImpact',
);
}
static Future<void> mediumImpact() async {
await SystemChannels.platform.invokeMethod<void>(
'HapticFeedback.vibrate',
'HapticFeedbackType.mediumImpact',
);
}
static Future<void> heavyImpact() async {
await SystemChannels.platform.invokeMethod<void>(
'HapticFeedback.vibrate',
'HapticFeedbackType.heavyImpact',
);
}
static Future<void> selectionClick() async {
await SystemChannels.platform.invokeMethod<void>(
'HapticFeedback.vibrate',
'HapticFeedbackType.selectionClick',
);
}
static Future<void> vibrate() async {
await SystemChannels.platform.invokeMethod<void>('HapticFeedback.vibrate');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment