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.

DebugPage.dart 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:touch_demonstrator/src/blocs/BlocProvider.dart';
  4. import 'package:touch_demonstrator/model/touchData.dart';
  5. import 'package:touch_demonstrator/src/blocs/bluetoothBloc.dart';
  6. class DebugView extends StatefulWidget {
  7. /// Screen that shows RAW data from the bluetooth device
  8. @override
  9. _DebugViewState createState() => _DebugViewState();
  10. }
  11. class _DebugViewState extends State<DebugView> {
  12. ScrollController _scrollController;
  13. static const TextStyle textStyleWhite = TextStyle(color: Colors.white);
  14. static const TextStyle textStyleBlack = TextStyle(color: Colors.black);
  15. @override
  16. void initState() {
  17. super.initState();
  18. _scrollController = ScrollController();
  19. }
  20. void _scrollList() {
  21. Future.delayed(Duration(milliseconds: 50), () {
  22. _scrollController.animateTo(_scrollController.position.maxScrollExtent,
  23. duration: new Duration(milliseconds: 500), curve: Curves.easeOut);
  24. });
  25. }
  26. @override
  27. Widget build(BuildContext context) {
  28. final BluetoothBloc bloc = BlocProvider.of(context).bluetoothBlocGetter;
  29. return Scaffold(
  30. appBar: AppBar(
  31. title: Text('Debug View Page'),
  32. ),
  33. body: SafeArea(
  34. child: Column(
  35. children: <Widget>[
  36. _buildHeaderDebugPage(context),
  37. // Divider(),
  38. StreamBuilder<List<TouchData>>(
  39. key: Key('ListTouchData'),
  40. stream: bloc.getHistory$,
  41. builder: (BuildContext context,
  42. AsyncSnapshot<List<TouchData>> snapshot) {
  43. if (snapshot.hasData) {
  44. _scrollList();
  45. print('${snapshot.data.length}');
  46. Color colorOfContainer;
  47. return Expanded(
  48. child: SizedBox(
  49. height: 50.0,
  50. child: ListView.builder(
  51. reverse: false,
  52. controller: _scrollController,
  53. scrollDirection: Axis.vertical,
  54. itemCount: snapshot.data.length,
  55. itemExtent: 33.0,
  56. itemBuilder: (context, i) {
  57. return buildRowOfTouchData(
  58. colorOfContainer, i, snapshot);
  59. }),
  60. ));
  61. } else {
  62. return Container();
  63. }
  64. }),
  65. ],
  66. ),
  67. ),
  68. );
  69. }
  70. Container _buildHeaderDebugPage(BuildContext context) {
  71. return Container(
  72. color: Theme.of(context).accentColor,
  73. child: Padding(
  74. padding: const EdgeInsets.all(8.0),
  75. child: Row(
  76. children: <Widget>[
  77. debugListItem('#', flexItem: 1),
  78. debugListItem('Finger'),
  79. debugListItem('Event'),
  80. debugListItem('X'),
  81. debugListItem('Y'),
  82. ],
  83. ),
  84. ),
  85. );
  86. }
  87. Container buildRowOfTouchData(Color colorOfContainer, int _index,
  88. AsyncSnapshot<List<TouchData>> snapshot) {
  89. var _textStyleDebug;
  90. var _fingerNrText = '${snapshot.data[_index].fingerNumber}';
  91. var _eventText;
  92. var _xText = '${snapshot.data[_index].x.toString().padLeft(4, ' ')}';
  93. var _yText = '${snapshot.data[_index].y.toString().padLeft(4, ' ')}';
  94. if ((snapshot.data[_index].event) == 1) {
  95. _eventText = 'MOVE';
  96. _textStyleDebug = textStyleBlack;
  97. colorOfContainer = Colors.white;
  98. } else {
  99. _textStyleDebug = textStyleWhite;
  100. if ((snapshot.data[_index].event) == 4) {
  101. colorOfContainer = Colors.teal;
  102. _eventText = 'DOWN';
  103. } else if((snapshot.data[_index].event) == 5){
  104. _eventText = 'UP';
  105. colorOfContainer = Colors.purple;
  106. } else {
  107. print('Default ${snapshot.data[_index]}');
  108. return Container();
  109. }
  110. }
  111. return Container(
  112. color: colorOfContainer,
  113. child: Row(
  114. children: <Widget>[
  115. debugListItem('$_index', flexItem: 1, styleText: _textStyleDebug),
  116. debugListItem(_fingerNrText, styleText: _textStyleDebug),
  117. debugListItem(_eventText, styleText: _textStyleDebug),
  118. debugListItem(_xText, styleText: _textStyleDebug),
  119. debugListItem(_yText, styleText: _textStyleDebug),
  120. ],
  121. ),
  122. );
  123. }
  124. Expanded debugListItem(String textItem,
  125. {int flexItem = 2, TextStyle styleText = textStyleWhite}) {
  126. return Expanded(
  127. flex: flexItem,
  128. child: Center(
  129. child: Text(textItem, style: styleText),
  130. ),
  131. );
  132. }
  133. }