Masterarbeit Richard Stern. Flutter App, sich mit einem Bluetooth-Gerät verbindet und Berührungen auf einem Sensor visualisiert.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vibrate.dart 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'dart:async';
  2. import 'package:flutter/services.dart';
  3. enum FeedbackType {
  4. success,
  5. error,
  6. warning,
  7. selection,
  8. impact,
  9. heavy,
  10. medium,
  11. light
  12. }
  13. class Vibrate {
  14. static const MethodChannel _channel = const MethodChannel('vibrate');
  15. static const Duration _DEFAULT_VIBRATION_DURATION =
  16. const Duration(milliseconds: 500);
  17. /// Vibrate for 500ms on Android, and for the default time on iOS (about 500ms as well)
  18. static Future vibrate() => _channel.invokeMethod(
  19. 'vibrate', {"duration": _DEFAULT_VIBRATION_DURATION.inMilliseconds});
  20. /// Whether the device can actually vibrate or not
  21. static Future<bool> get canVibrate async {
  22. final bool isOn = await _channel.invokeMethod('canVibrate');
  23. return isOn;
  24. }
  25. static void feedback(FeedbackType type) {
  26. switch (type) {
  27. case FeedbackType.impact:
  28. _channel.invokeMethod('impact');
  29. break;
  30. case FeedbackType.error:
  31. _channel.invokeMethod('error');
  32. break;
  33. case FeedbackType.success:
  34. _channel.invokeMethod('success');
  35. break;
  36. case FeedbackType.warning:
  37. _channel.invokeMethod('warning');
  38. break;
  39. case FeedbackType.selection:
  40. _channel.invokeMethod('selection');
  41. break;
  42. case FeedbackType.heavy:
  43. _channel.invokeMethod('heavy');
  44. break;
  45. case FeedbackType.medium:
  46. _channel.invokeMethod('medium');
  47. break;
  48. case FeedbackType.light:
  49. _channel.invokeMethod('light');
  50. break;
  51. default:
  52. }
  53. }
  54. /// Vibrates with [pauses] in between each vibration
  55. /// Will always vibrate once before the first pause
  56. /// and once after the last pause
  57. static Future vibrateWithPauses(Iterable<Duration> pauses) async {
  58. for (Duration d in pauses) {
  59. vibrate();
  60. //Because the native vibration is not awaited, we need to wait for
  61. //the vibration to end before launching another one
  62. await new Future.delayed(_DEFAULT_VIBRATION_DURATION);
  63. await new Future.delayed(d);
  64. }
  65. vibrate();
  66. }
  67. }