|
@@ -1,14 +1,15 @@
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
+import 'package:vnote_device_plugin/consts/types.dart';
|
|
|
import 'package:vnote_device_plugin/devices/temp.dart';
|
|
|
import 'package:vnoteapp/components/dialog_number.dart';
|
|
|
+import 'package:vnoteapp/managers/interfaces/models/device.dart';
|
|
|
import 'package:vnoteapp/managers/interfaces/permission.dart';
|
|
|
import 'package:vnoteapp/pages/check/models/form.dart';
|
|
|
+import 'package:vnoteapp/pages/check/widgets/device_controller.dart';
|
|
|
import 'package:vnoteapp/pages/check/widgets/exam_configurable/exam_card.dart';
|
|
|
-import 'package:vnoteapp/pages/check/widgets/exam_device_connect_status/connect.dart';
|
|
|
-import 'package:vnoteapp/pages/check/widgets/exam_device_connect_status/connect_disconnected.dart';
|
|
|
-import 'package:vnoteapp/pages/check/widgets/exam_device_connect_status/connect_fail.dart';
|
|
|
-import 'package:vnoteapp/pages/check/widgets/exam_device_connect_status/connect_success.dart';
|
|
|
+import 'package:vnoteapp/pages/medical/models/worker.dart';
|
|
|
+import 'package:vnoteapp/pages/medical/widgets/device_status.dart';
|
|
|
|
|
|
// ignore: must_be_immutable
|
|
|
class ExamBodyTemperature extends StatefulWidget {
|
|
@@ -26,50 +27,53 @@ class ExamBodyTemperature extends StatefulWidget {
|
|
|
State<ExamBodyTemperature> createState() => _ExamBodyTemperatureState();
|
|
|
}
|
|
|
|
|
|
+/// TODO 先完成配置设备的替换 还需要优化
|
|
|
class _ExamBodyTemperatureState extends State<ExamBodyTemperature> {
|
|
|
var permissionManager = Get.find<IPermissionManager>();
|
|
|
- late final TempDeviceWorker worker = TempDeviceWorker(
|
|
|
- mac: 'D0:05:00:00:00:67',
|
|
|
- model: 'YHW-6',
|
|
|
- );
|
|
|
-
|
|
|
- /// 设备连接失败的状态
|
|
|
- bool _connectFailStatus = false;
|
|
|
-
|
|
|
- /// 设备连接中断的状态
|
|
|
- bool _connectDisconnectedStatus = false;
|
|
|
-
|
|
|
- /// 设备连接成功的状态
|
|
|
- bool _connectSuccessStatus = false;
|
|
|
+ final controller = Get.find<DeviceController>();
|
|
|
+ WorkerStatus connectStatus = WorkerStatus.connecting;
|
|
|
+ late TempDeviceWorker worker;
|
|
|
+
|
|
|
+ Future<void> currentDevice() async {
|
|
|
+ DeviceModel? device = await controller.getDevice(DeviceTypes.TEMP);
|
|
|
+ if (device.isNull) {
|
|
|
+ connectStatus = WorkerStatus.unboundDevice;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ worker =
|
|
|
+ TempDeviceWorker(model: device?.model ?? '', mac: device?.mac ?? '');
|
|
|
+ loadListeners();
|
|
|
+ }
|
|
|
|
|
|
- /// 设备是否连接中
|
|
|
- bool _isConnect = false;
|
|
|
@override
|
|
|
void initState() {
|
|
|
- getPermission();
|
|
|
- worker.successEvent.addListener(_onSuccess);
|
|
|
- worker.connectErrorEvent.addListener(_onConnectFail);
|
|
|
- worker.connectedEvent.addListener(_onConnectSuccess);
|
|
|
- worker.disconnectedEvent.addListener(_onDisconnected);
|
|
|
+ currentDevice();
|
|
|
|
|
|
- connect();
|
|
|
super.initState();
|
|
|
}
|
|
|
|
|
|
Future<void> connect() async {
|
|
|
- _connectFailStatus = false;
|
|
|
- _isConnect = true;
|
|
|
- _connectSuccessStatus = false;
|
|
|
- _connectDisconnectedStatus = false;
|
|
|
setState(() {});
|
|
|
await worker.connect();
|
|
|
}
|
|
|
|
|
|
+ void loadListeners() {
|
|
|
+ worker.successEvent.addListener(_onSuccess);
|
|
|
+ worker.connectErrorEvent.addListener(_onConnectFail);
|
|
|
+ worker.connectedEvent.addListener(_onConnectSuccess);
|
|
|
+ worker.disconnectedEvent.addListener(_onDisconnected);
|
|
|
+ worker.tempTooLowEvent.addListener(_onTempTooLowOrTooHeigh);
|
|
|
+ worker.tempTooHighEvent.addListener(_onTempTooLowOrTooHeigh);
|
|
|
+ worker.connect();
|
|
|
+ }
|
|
|
+
|
|
|
Future<void> disconnect() async {
|
|
|
worker.connectErrorEvent.removeListener(_onConnectFail);
|
|
|
worker.connectedEvent.removeListener(_onConnectSuccess);
|
|
|
worker.successEvent.removeListener(_onSuccess);
|
|
|
worker.disconnectedEvent.removeListener(_onDisconnected);
|
|
|
+ worker.tempTooLowEvent.removeListener(_onTempTooLowOrTooHeigh);
|
|
|
+ worker.tempTooHighEvent.removeListener(_onTempTooLowOrTooHeigh);
|
|
|
await worker.disconnect();
|
|
|
}
|
|
|
|
|
@@ -83,41 +87,34 @@ class _ExamBodyTemperatureState extends State<ExamBodyTemperature> {
|
|
|
setState(() {
|
|
|
widget.currentInputValue = e.toString();
|
|
|
widget.bodyTemperatureInput!.call(widget.currentInputValue);
|
|
|
- _isConnect = false;
|
|
|
+ connectStatus = WorkerStatus.connected;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
void _onConnectFail(sender, e) {
|
|
|
print('连接设备失败');
|
|
|
- _connectFailStatus = true;
|
|
|
- _connectSuccessStatus = false;
|
|
|
- _connectDisconnectedStatus = false;
|
|
|
- _isConnect = false;
|
|
|
+ connectStatus = WorkerStatus.connectionFailed;
|
|
|
+ worker.connect();
|
|
|
setState(() {});
|
|
|
}
|
|
|
|
|
|
void _onConnectSuccess(sender, e) {
|
|
|
- _connectSuccessStatus = true;
|
|
|
- _isConnect = false;
|
|
|
- _connectFailStatus = false;
|
|
|
- _connectDisconnectedStatus = false;
|
|
|
+ connectStatus = WorkerStatus.connected;
|
|
|
setState(() {});
|
|
|
}
|
|
|
|
|
|
- void _onDisconnected(sender, e) {
|
|
|
- print('设备连接中断');
|
|
|
- _connectDisconnectedStatus = true;
|
|
|
- _connectSuccessStatus = false;
|
|
|
- _connectFailStatus = false;
|
|
|
- _isConnect = false;
|
|
|
+ void _onTempTooLowOrTooHeigh(sender, e) {
|
|
|
+ widget.currentInputValue = e.toString();
|
|
|
+ widget.bodyTemperatureInput!.call(widget.currentInputValue);
|
|
|
+ connectStatus = WorkerStatus.connected;
|
|
|
setState(() {});
|
|
|
}
|
|
|
|
|
|
- Future<void> getPermission() async {
|
|
|
- await permissionManager.requestLocationPermission();
|
|
|
- await permissionManager.requestBluetoothConnectPermission();
|
|
|
- await permissionManager.requestBluetoothAdvertisePermission();
|
|
|
- await permissionManager.requestBluetoothScanPermission();
|
|
|
+ void _onDisconnected(sender, e) {
|
|
|
+ connectStatus = WorkerStatus.disconnected;
|
|
|
+ worker.connect();
|
|
|
+ print('设备连接中断');
|
|
|
+ setState(() {});
|
|
|
}
|
|
|
|
|
|
@override
|
|
@@ -125,16 +122,7 @@ class _ExamBodyTemperatureState extends State<ExamBodyTemperature> {
|
|
|
return Stack(
|
|
|
children: [
|
|
|
_buildTemperature(),
|
|
|
- if (_connectFailStatus)
|
|
|
- DeviceConnectFail(
|
|
|
- connect: () => connect(),
|
|
|
- ),
|
|
|
- if (_connectSuccessStatus) const DeviceConnectSuccess(),
|
|
|
- if (_isConnect) const DeviceConnect(),
|
|
|
- if (_connectDisconnectedStatus)
|
|
|
- DeviceConnectDisconnected(
|
|
|
- connect: () => connect(),
|
|
|
- ),
|
|
|
+ DeviceStatus(connectStatus: connectStatus),
|
|
|
],
|
|
|
);
|
|
|
}
|