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.

main.dart 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import 'package:flutter/material.dart';
  2. import 'package:vibrate/vibrate.dart';
  3. void main() => runApp(new MyApp());
  4. class MyApp extends StatefulWidget {
  5. @override
  6. _MyAppState createState() => new _MyAppState();
  7. }
  8. class _MyAppState extends State<MyApp> {
  9. bool _canVibrate = true;
  10. final Iterable<Duration> pauses = [
  11. const Duration(milliseconds: 500),
  12. const Duration(milliseconds: 1000),
  13. const Duration(milliseconds: 500),
  14. ];
  15. @override
  16. initState() {
  17. super.initState();
  18. init();
  19. }
  20. init() async {
  21. bool canVibrate = await Vibrate.canVibrate;
  22. setState(() {
  23. _canVibrate = canVibrate;
  24. _canVibrate
  25. ? print("This device can vibrate")
  26. : print("This device cannot vibrate");
  27. });
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return new MaterialApp(
  32. home: new Scaffold(
  33. appBar: new AppBar(title: new Text('Haptic Feedback Example')),
  34. body: new Center(
  35. child: new Column(children: <Widget>[
  36. new ListTile(
  37. title: new Text("Vibrate"),
  38. leading: new Icon(Icons.vibration, color: Colors.teal),
  39. onTap: !_canVibrate
  40. ? null
  41. : () {
  42. Vibrate.vibrate();
  43. },
  44. ),
  45. new ListTile(
  46. title: new Text("Vibrate with Pauses"),
  47. leading: new Icon(Icons.vibration, color: Colors.brown),
  48. onTap: !_canVibrate
  49. ? null
  50. : () {
  51. Vibrate.vibrateWithPauses(pauses);
  52. },
  53. ),
  54. new Divider(height: 1.0),
  55. new ListTile(
  56. title: new Text("Impact"),
  57. leading: new Icon(Icons.tap_and_play, color: Colors.orange),
  58. onTap: !_canVibrate
  59. ? null
  60. : () {
  61. Vibrate.feedback(FeedbackType.impact);
  62. },
  63. ),
  64. new ListTile(
  65. title: new Text("Selection"),
  66. leading: new Icon(Icons.select_all, color: Colors.blue),
  67. onTap: !_canVibrate
  68. ? null
  69. : () {
  70. Vibrate.feedback(FeedbackType.selection);
  71. },
  72. ),
  73. new ListTile(
  74. title: new Text("Success"),
  75. leading: new Icon(Icons.check, color: Colors.green),
  76. onTap: !_canVibrate
  77. ? null
  78. : () {
  79. Vibrate.feedback(FeedbackType.success);
  80. },
  81. ),
  82. new ListTile(
  83. title: new Text("Warning"),
  84. leading: new Icon(Icons.warning, color: Colors.red),
  85. onTap: !_canVibrate
  86. ? null
  87. : () {
  88. Vibrate.feedback(FeedbackType.warning);
  89. },
  90. ),
  91. new ListTile(
  92. title: new Text("Error"),
  93. leading: new Icon(Icons.error, color: Colors.red),
  94. onTap: !_canVibrate
  95. ? null
  96. : () {
  97. Vibrate.feedback(FeedbackType.error);
  98. },
  99. ),
  100. new Divider(height: 1.0),
  101. new ListTile(
  102. title: new Text("Heavy"),
  103. leading:
  104. new Icon(Icons.notification_important, color: Colors.red),
  105. onTap: !_canVibrate
  106. ? null
  107. : () {
  108. Vibrate.feedback(FeedbackType.heavy);
  109. },
  110. ),
  111. new ListTile(
  112. title: new Text("Medium"),
  113. leading:
  114. new Icon(Icons.notification_important, color: Colors.green),
  115. onTap: !_canVibrate
  116. ? null
  117. : () {
  118. Vibrate.feedback(FeedbackType.medium);
  119. },
  120. ),
  121. new ListTile(
  122. title: new Text("Light"),
  123. leading: new Icon(Icons.notification_important,
  124. color: Colors.yellow[700]),
  125. onTap: !_canVibrate
  126. ? null
  127. : () {
  128. Vibrate.feedback(FeedbackType.light);
  129. },
  130. ),
  131. ]),
  132. ),
  133. ),
  134. );
  135. }
  136. }