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.

PageTouchPoints.dart 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import 'package:flutter/material.dart';
  2. import 'package:touch_demonstrator/ui/pageTouchPoints/AppBarPageTouchPoints.dart';
  3. import 'package:touch_demonstrator/ui/pageTouchPoints/SideBar.dart';
  4. import 'dart:core';
  5. import 'package:touch_demonstrator/src/blocs/BlocProvider.dart'; //bloc:
  6. import 'package:touch_demonstrator/ui/pageTouchPoints/ScanResultBottomSheet.dart';
  7. import 'package:touch_demonstrator/ui/pageTouchPoints/ButtonOrAnimation.dart';
  8. import 'package:touch_demonstrator/ui/pageTouchPoints/Logo.dart';
  9. import 'package:touch_demonstrator/ui/pageTouchPoints/Sensor.dart';
  10. import 'package:flutter_blue/flutter_blue.dart';
  11. import 'package:vibrate/vibrate.dart';
  12. import 'package:touch_demonstrator/model/vibrate.dart';
  13. class PageTouchPoints extends StatefulWidget {
  14. PageTouchPoints({Key key, this.title}) : super(key: key);
  15. final String title;
  16. @override
  17. _PageTouchPointsState createState() => new _PageTouchPointsState();
  18. }
  19. class _PageTouchPointsState extends State<PageTouchPoints> {
  20. final GlobalKey<ScaffoldState> mScaffoldState =
  21. new GlobalKey<ScaffoldState>();
  22. static Modal modal;
  23. static bool firstTime = true;
  24. @override
  25. void dispose() {
  26. final bBloc = BlocProvider.of(context).bluetoothBlocGetter;
  27. bBloc.disconnect.add(null); //disconnect everything
  28. super.dispose();
  29. }
  30. @override
  31. void didChangeDependencies() {
  32. super.didChangeDependencies();
  33. print('didChangeDependencies');
  34. /// Manages Snackbar "no device found" and "Bluetooth off" and toggles the debugmode.
  35. final bBloc = BlocProvider.of(context).bluetoothBlocGetter;
  36. final debugBloc = BlocProvider.of(context).debugBlocGetter;
  37. _showSnackbar(String textInSnackBar) {
  38. /// Shows Snackbar for 0.5 s with String textInSnackBar in it
  39. print('snackbar $textInSnackBar');
  40. mScaffoldState.currentState.showSnackBar(SnackBar(
  41. content: Text(
  42. textInSnackBar,
  43. style: TextStyle(fontSize: 15),
  44. ),
  45. duration: Duration(milliseconds: 1000),
  46. ));
  47. }
  48. _toggleDebug(bool debugStatus) {
  49. vibrate(FeedbackType.success);
  50. _showSnackbar('Debug View: ${debugStatus ? 'enabled' : 'disabled'}!');
  51. }
  52. if (firstTime) {
  53. firstTime = false;
  54. modal = new Modal();
  55. bBloc.devicesFound$.listen((device) {
  56. if (device.length == 0) {
  57. print('Snackbar: No device found');
  58. _showSnackbar('No device found');
  59. vibrateDelayed(FeedbackType.warning, Duration(milliseconds: 150));
  60. } else {
  61. modal.connectBottomSheet(context, device);
  62. }
  63. });
  64. debugBloc.debugEnabledStatus$.listen((data) => _toggleDebug(data));
  65. bBloc.bluetoothState$
  66. .where((bluetoothState) => bluetoothState == BluetoothState.off)
  67. .listen(
  68. (bluetoothState) => _showBluetoothOffSnackbar(bluetoothState));
  69. bBloc.bluetoothState$
  70. .where((bluetoothState) => bluetoothState == BluetoothState.on)
  71. .listen((_) => mScaffoldState.currentState.removeCurrentSnackBar());
  72. } else {
  73. print('REMOVE current snack bar');
  74. mScaffoldState.currentState.removeCurrentSnackBar();
  75. }
  76. }
  77. _showBluetoothOffSnackbar(BluetoothState bluetoothState) {
  78. /// Shows Snackbar if Bluetooth is off to inform user.
  79. var textInSnackbar = 'Bluetooth is off!';
  80. print('snackbar $textInSnackbar');
  81. mScaffoldState.currentState.showSnackBar(SnackBar(
  82. backgroundColor: Colors.red,
  83. content: Row(
  84. mainAxisAlignment: MainAxisAlignment.start,
  85. children: <Widget>[
  86. Icon(Icons.warning),
  87. Padding(
  88. padding: EdgeInsets.only(left: 10.0),
  89. child: Text(
  90. textInSnackbar,
  91. textAlign: TextAlign.center,
  92. style: TextStyle(fontSize: 25),
  93. ),
  94. ),
  95. ],
  96. ),
  97. duration: Duration(days: 1),
  98. ));
  99. }
  100. @override
  101. Widget build(BuildContext context) {
  102. /// build UI for the main screen in the app
  103. return Scaffold(
  104. key: mScaffoldState,
  105. // necessary for toast message
  106. appBar: buildAppBarPageTouchPoints(context),
  107. drawer: LeftDrawer(),
  108. body: SafeArea(child: OrientationBuilder(builder: (context, orientation) {
  109. return _buildBody(orientation);
  110. // return _buildVerticalLayout();
  111. })),
  112. );
  113. }
  114. _buildBody(Orientation orientation) {
  115. if (orientation == Orientation.portrait)
  116. return _buildVerticalLayout();
  117. else
  118. return _buildHorizontalLayout();
  119. }
  120. static const _heightLogo = 100.0;
  121. _buildVerticalLayout() {
  122. /// Layout for vertical orientation
  123. EdgeInsets devicePadding = MediaQuery.of(context).padding;
  124. return Padding(
  125. padding: const EdgeInsets.all(5.0),
  126. child: Column(
  127. mainAxisAlignment: MainAxisAlignment.start,
  128. children: <Widget>[
  129. Container(height: devicePadding.top),
  130. LogoWithText(_heightLogo),
  131. Expanded(child: Sensor()),
  132. ConnectButtonWithAnimations(),
  133. ],
  134. ),
  135. );
  136. }
  137. _buildHorizontalLayout() {
  138. /// Layout for horizontal orientation
  139. return Padding(
  140. padding: const EdgeInsets.all(8.0),
  141. child: Column(children: <Widget>[
  142. Row(
  143. mainAxisAlignment: MainAxisAlignment.center,
  144. children: <Widget>[
  145. Column(
  146. mainAxisAlignment: MainAxisAlignment.start,
  147. children: <Widget>[
  148. LogoWithText(_heightLogo),
  149. ConnectButtonWithAnimations(),
  150. ],
  151. ),
  152. Column(
  153. children: <Widget>[
  154. Sensor(),
  155. ],
  156. ),
  157. ],
  158. ),
  159. ]),
  160. );
  161. }
  162. }