|
@@ -3,6 +3,7 @@ import 'dart:convert';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:flutter/services.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
+import 'package:vitalapp/pages/medical/widgets/device_status_position.dart';
|
|
|
import 'package:vnote_device_plugin/consts/types.dart';
|
|
|
import 'package:vnote_device_plugin/devices/nibp.dart';
|
|
|
import 'package:vnote_device_plugin/models/exams/nibp.dart';
|
|
@@ -185,7 +186,7 @@ class _ExamBloodPressureState extends State<BloodPressure> {
|
|
|
late NibpDeviceController nibp;
|
|
|
NibpDeviceWorker? worker;
|
|
|
int liveValue = 0;
|
|
|
-
|
|
|
+ int errorCount = 0; //设备重连失败次数
|
|
|
late NibpExamValue? value = NibpExamValue(
|
|
|
diastolicPressure: controller.diagnosisDataValue['NIBP']?['Sbp'],
|
|
|
// int.parse(controller.diagnosisDataValue['NIBP']?['Sbp'] ?? '0'),
|
|
@@ -243,7 +244,6 @@ class _ExamBloodPressureState extends State<BloodPressure> {
|
|
|
void dispose() {
|
|
|
disconnect();
|
|
|
worker?.dispose();
|
|
|
- print('${worker!.type}disposed. ');
|
|
|
super.dispose();
|
|
|
}
|
|
|
|
|
@@ -282,18 +282,30 @@ class _ExamBloodPressureState extends State<BloodPressure> {
|
|
|
|
|
|
void _onConnectFail(sender, e) {
|
|
|
print('连接设备失败');
|
|
|
- _connectStatus = WorkerStatus.connectionFailed;
|
|
|
- setState(() {});
|
|
|
- }
|
|
|
|
|
|
- void _onConnectSuccess(sender, e) {
|
|
|
- _connectStatus = WorkerStatus.connected;
|
|
|
- setState(() {});
|
|
|
+ if (errorCount < 3) {
|
|
|
+ worker?.connect();
|
|
|
+ }
|
|
|
+ setState(() {
|
|
|
+ errorCount++;
|
|
|
+ _connectStatus = WorkerStatus.connectionFailed;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
void _onDisconnected(sender, e) {
|
|
|
print('设备连接中断');
|
|
|
- _connectStatus = WorkerStatus.disconnected;
|
|
|
+
|
|
|
+ if (errorCount < 3) {
|
|
|
+ worker?.connect();
|
|
|
+ }
|
|
|
+ setState(() {
|
|
|
+ errorCount++;
|
|
|
+ _connectStatus = WorkerStatus.disconnected;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ void _onConnectSuccess(sender, e) {
|
|
|
+ _connectStatus = WorkerStatus.connected;
|
|
|
setState(() {});
|
|
|
}
|
|
|
|
|
@@ -348,12 +360,46 @@ class _ExamBloodPressureState extends State<BloodPressure> {
|
|
|
),
|
|
|
),
|
|
|
),
|
|
|
- // _buildLeftOrRightBloodPressure(),
|
|
|
- DeviceStatus(connectStatus: _connectStatus),
|
|
|
+ if (errorCount < 3)
|
|
|
+ DeviceStatusPosition(
|
|
|
+ deviceStatus: DeviceStatus(connectStatus: _connectStatus),
|
|
|
+ ),
|
|
|
+ if (errorCount >= 3) _buildErrorButton(),
|
|
|
],
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /// 需要封装一下
|
|
|
+ Widget _buildErrorButton() {
|
|
|
+ return DeviceStatusPosition(
|
|
|
+ deviceStatus: Row(
|
|
|
+ children: [
|
|
|
+ const Text(
|
|
|
+ '请确认设备是否启动',
|
|
|
+ style: TextStyle(fontSize: 24, color: Colors.red),
|
|
|
+ ),
|
|
|
+ const SizedBox(
|
|
|
+ width: 8,
|
|
|
+ ),
|
|
|
+ IconButton(
|
|
|
+ onPressed: () {
|
|
|
+ worker?.connect();
|
|
|
+ setState(() {
|
|
|
+ _connectStatus = WorkerStatus.connecting;
|
|
|
+ errorCount = 0;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ icon: const Icon(Icons.refresh),
|
|
|
+ iconSize: 32,
|
|
|
+ ),
|
|
|
+ const SizedBox(
|
|
|
+ width: 32,
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
Widget _buildLeftOrRightBloodPressure() {
|
|
|
return Positioned(
|
|
|
top: 130,
|