Created
July 24, 2020 00:01
-
-
Save avuenja/db8ba15f48a21e6fce70ab4d0816e3e1 to your computer and use it in GitHub Desktop.
Flutter: Haptic Feedback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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