diff --git a/open_earable/lib/sensor_data_tab/earable_3d_model.dart b/open_earable/lib/sensor_data_tab/earable_3d_model.dart index 5730cf3..f45e3e6 100644 --- a/open_earable/lib/sensor_data_tab/earable_3d_model.dart +++ b/open_earable/lib/sensor_data_tab/earable_3d_model.dart @@ -1,4 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:open_earable/ble_controller.dart'; +import 'package:open_earable/widgets/earable_not_connected_warning.dart'; +import 'package:provider/provider.dart'; import 'dart:async'; import 'package:three_dart/three_dart.dart' as three; import 'package:three_dart_jsm/three_dart_jsm.dart' as three_jsm; @@ -88,52 +91,57 @@ class _Earable3DModelState extends State { @override Widget build(BuildContext context) { - return Column( - children: [ - Padding( - padding: const EdgeInsets.all(8.0), - // child: Text(title, style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)), - ), - Expanded(child: LayoutBuilder( - builder: (BuildContext context, BoxConstraints constraints) { - width = constraints.maxWidth; - height = constraints.maxHeight; - Color c = Theme.of(context).colorScheme.background; - _sceneBackground = three.Color.fromArray([c.red, c.green, c.blue]); - initSize(context); - return Column( - children: [ - Stack( - children: [ - Container( - width: width, - height: height, - color: Theme.of(context).colorScheme.background, - child: Builder(builder: (BuildContext context) { - if (kIsWeb) { - return three3dRender.isInitialized - ? HtmlElementView( - viewType: - three3dRender.textureId!.toString()) - : Container(); - } else { - return three3dRender.isInitialized - ? Texture(textureId: three3dRender.textureId!) - : Container(); - } - })), - ], - ), - ], - ); - }, - )), - Padding( - padding: EdgeInsets.only(bottom: 16), - child: Text( - "Yaw: ${(_yaw * 180 / pi).toStringAsFixed(1)}°\nPitch: ${(_pitch * 180 / pi).toStringAsFixed(1)}°\nRoll: ${(_roll * 180 / pi).toStringAsFixed(1)}°")) - ], - ); + if (!Provider.of(context).connected) { + return EarableNotConnectedWarning(); + } else { + return Column( + children: [ + Padding( + padding: const EdgeInsets.all(8.0), + // child: Text(title, style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)), + ), + Expanded(child: LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + width = constraints.maxWidth; + height = constraints.maxHeight; + Color c = Theme.of(context).colorScheme.background; + _sceneBackground = + three.Color.fromArray([c.red, c.green, c.blue]); + initSize(context); + return Column( + children: [ + Stack( + children: [ + Container( + width: width, + height: height, + color: Theme.of(context).colorScheme.background, + child: Builder(builder: (BuildContext context) { + if (kIsWeb) { + return three3dRender.isInitialized + ? HtmlElementView( + viewType: + three3dRender.textureId!.toString()) + : Container(); + } else { + return three3dRender.isInitialized + ? Texture(textureId: three3dRender.textureId!) + : Container(); + } + })), + ], + ), + ], + ); + }, + )), + Padding( + padding: EdgeInsets.only(bottom: 16), + child: Text( + "Yaw: ${(_yaw * 180 / pi).toStringAsFixed(1)}°\nPitch: ${(_pitch * 180 / pi).toStringAsFixed(1)}°\nRoll: ${(_roll * 180 / pi).toStringAsFixed(1)}°")) + ], + ); + } } // Platform messages are asynchronous, so we initialize in an async method. diff --git a/open_earable/lib/sensor_data_tab/sensor_chart.dart b/open_earable/lib/sensor_data_tab/sensor_chart.dart index 1b80915..ed34a10 100644 --- a/open_earable/lib/sensor_data_tab/sensor_chart.dart +++ b/open_earable/lib/sensor_data_tab/sensor_chart.dart @@ -1,9 +1,12 @@ import 'dart:async'; import 'package:flutter/scheduler.dart'; +import 'package:open_earable/ble_controller.dart'; +import 'package:open_earable/widgets/earable_not_connected_warning.dart'; import 'package:open_earable_flutter/src/open_earable_flutter.dart'; import 'package:flutter/material.dart'; import 'package:charts_flutter/flutter.dart' as charts; +import 'package:provider/provider.dart'; import 'package:simple_kalman/simple_kalman.dart'; import 'package:collection/collection.dart'; import 'dart:math'; @@ -155,7 +158,9 @@ class _EarableDataChartState extends State { _minY = -25; _maxY = 25; } - _setupListeners(); + if (_openEarable.bleManager.connected) { + _setupListeners(); + } } @override @@ -172,6 +177,9 @@ class _EarableDataChartState extends State { @override Widget build(BuildContext context) { + if (!Provider.of(context).connected) { + return EarableNotConnectedWarning(); + } if (_title == 'Pressure' || _title == 'Temperature') { seriesList = [ charts.Series( diff --git a/open_earable/lib/sensor_data_tab/sensor_data_tab.dart b/open_earable/lib/sensor_data_tab/sensor_data_tab.dart index b89b53e..4761569 100644 --- a/open_earable/lib/sensor_data_tab/sensor_data_tab.dart +++ b/open_earable/lib/sensor_data_tab/sensor_data_tab.dart @@ -1,10 +1,12 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import 'package:open_earable/ble_controller.dart'; import 'package:open_earable/sensor_data_tab/earable_3d_model.dart'; import 'package:open_earable/widgets/earable_not_connected_warning.dart'; import 'package:open_earable_flutter/src/open_earable_flutter.dart'; import 'package:open_earable/sensor_data_tab/sensor_chart.dart'; +import 'package:provider/provider.dart'; class SensorDataTab extends StatefulWidget { final OpenEarable _openEarable; @@ -58,14 +60,6 @@ class _SensorDataTabState extends State @override Widget build(BuildContext context) { - if (!_openEarable.bleManager.connected) { - return EarableNotConnectedWarning(); - } else { - return _buildSensorDataTabs(); - } - } - - Widget _buildSensorDataTabs() { return Scaffold( backgroundColor: Theme.of(context).colorScheme.background, appBar: PreferredSize(