|
@@ -4,6 +4,7 @@ import 'package:vnote_device_plugin/devices/temp.dart';
|
|
|
import 'package:vnoteapp/components/alert_dialog.dart';
|
|
|
import 'package:vnoteapp/pages/check/models/form.dart';
|
|
|
import 'package:vnoteapp/pages/check/widgets/exam_configurable/exam_card.dart';
|
|
|
+import 'package:vnoteapp/store/store.dart';
|
|
|
|
|
|
class ExamBodyTemperature extends StatefulWidget {
|
|
|
const ExamBodyTemperature({
|
|
@@ -73,7 +74,14 @@ class _ExamBodyTemperatureState extends State<ExamBodyTemperature> {
|
|
|
|
|
|
|
|
|
final result = await Get.dialog(
|
|
|
- Temperature(currentFormObject: widget.currentFormObject));
|
|
|
+ Temperature(
|
|
|
+ currentFormObject: widget.currentFormObject,
|
|
|
+ temperature: widget.currentInputValue,
|
|
|
+ ),
|
|
|
+ barrierDismissible: false,
|
|
|
+ );
|
|
|
+ widget.specialInput?.call(result);
|
|
|
+ print(result);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -81,8 +89,11 @@ class Temperature extends StatefulWidget {
|
|
|
const Temperature({
|
|
|
super.key,
|
|
|
required this.currentFormObject,
|
|
|
+ this.temperature,
|
|
|
});
|
|
|
final FormObject currentFormObject;
|
|
|
+ final String? temperature;
|
|
|
+
|
|
|
@override
|
|
|
State<Temperature> createState() => _TemperatureState();
|
|
|
}
|
|
@@ -92,106 +103,180 @@ class _TemperatureState extends State<Temperature> {
|
|
|
mac: '44:A6:E5:16:62:33',
|
|
|
model: 'DT-8836',
|
|
|
);
|
|
|
- TextEditingController specialInputController = TextEditingController();
|
|
|
-
|
|
|
+ late TextEditingController specialInputController =
|
|
|
+ TextEditingController(text: widget.temperature ?? '00.0');
|
|
|
+ bool connectFailState = false;
|
|
|
+ bool connectSuccessState = false;
|
|
|
+ bool isConnect = false;
|
|
|
@override
|
|
|
void initState() {
|
|
|
connect();
|
|
|
+
|
|
|
worker.successEvent.addListener(_onSuccess);
|
|
|
+ worker.connectFailEvent.addListener(_onConnectFail);
|
|
|
+ worker.connectSuccessEvent.addListener(_onConnectSuccess);
|
|
|
|
|
|
super.initState();
|
|
|
}
|
|
|
|
|
|
Future<void> connect() async {
|
|
|
+ connectFailState = false;
|
|
|
+ isConnect = true;
|
|
|
+ connectSuccessState = false;
|
|
|
+ setState(() {});
|
|
|
await worker.connect();
|
|
|
}
|
|
|
|
|
|
Future<void> disconnect() async {
|
|
|
+ worker.connectFailEvent.removeListener(_onConnectFail);
|
|
|
+ worker.connectSuccessEvent.removeListener(_onConnectSuccess);
|
|
|
await worker.disconnect();
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
void dispose() {
|
|
|
- disconnect();
|
|
|
super.dispose();
|
|
|
}
|
|
|
|
|
|
void _onSuccess(_, double e) {
|
|
|
setState(() {
|
|
|
specialInputController.text = e.toString();
|
|
|
+ connectFailState = false;
|
|
|
+ connectSuccessState = false;
|
|
|
+ isConnect = false;
|
|
|
+ disconnect();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ void _onConnectFail(sender, e) {
|
|
|
+ print('连接设备失败');
|
|
|
+ connectFailState = true;
|
|
|
+ connectSuccessState = false;
|
|
|
+ isConnect = false;
|
|
|
+ setState(() {});
|
|
|
+ }
|
|
|
+
|
|
|
+ void _onConnectSuccess(sender, e) {
|
|
|
+ connectSuccessState = true;
|
|
|
+ connectFailState = false;
|
|
|
+ isConnect = false;
|
|
|
+ setState(() {});
|
|
|
+ }
|
|
|
+
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
return VAlertDialog(
|
|
|
title: widget.currentFormObject.label ?? '',
|
|
|
width: 600,
|
|
|
contentPadding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
|
|
|
- content: Row(
|
|
|
+ content: Column(
|
|
|
+ mainAxisSize: MainAxisSize.min,
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
children: [
|
|
|
- Container(
|
|
|
- width: 400,
|
|
|
- padding: const EdgeInsets.only(left: 15),
|
|
|
- child: TextFormField(
|
|
|
- keyboardType: TextInputType.number,
|
|
|
- style: const TextStyle(
|
|
|
- fontSize: 100,
|
|
|
- ),
|
|
|
- showCursor: false,
|
|
|
- controller: specialInputController,
|
|
|
- decoration: const InputDecoration(
|
|
|
- labelStyle: TextStyle(
|
|
|
- fontSize: 100,
|
|
|
+ connectFailState
|
|
|
+ ? const Text(
|
|
|
+ '设备连接失败',
|
|
|
+ style: TextStyle(
|
|
|
+ color: Colors.red,
|
|
|
+ fontSize: 25,
|
|
|
+ ),
|
|
|
+ textAlign: TextAlign.left,
|
|
|
+ )
|
|
|
+ : const SizedBox(),
|
|
|
+ connectSuccessState
|
|
|
+ ? const Text(
|
|
|
+ '设备连接成功',
|
|
|
+ style: TextStyle(
|
|
|
+ color: Colors.green,
|
|
|
+ fontSize: 25,
|
|
|
+ ),
|
|
|
+ textAlign: TextAlign.left,
|
|
|
+ )
|
|
|
+ : const SizedBox(),
|
|
|
+ Row(
|
|
|
+ children: [
|
|
|
+ Container(
|
|
|
+ width: 350,
|
|
|
+ padding: const EdgeInsets.only(left: 15),
|
|
|
+ child: TextFormField(
|
|
|
+ keyboardType: TextInputType.number,
|
|
|
+ style: const TextStyle(
|
|
|
+ fontSize: 100,
|
|
|
+ ),
|
|
|
+ showCursor: false,
|
|
|
+ controller: specialInputController,
|
|
|
+ decoration: const InputDecoration(
|
|
|
+ labelStyle: TextStyle(
|
|
|
+ fontSize: 100,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
),
|
|
|
),
|
|
|
- ),
|
|
|
- ),
|
|
|
- specialInputController.text == ''
|
|
|
- ? const Expanded(
|
|
|
- child: Row(children: [
|
|
|
- Expanded(
|
|
|
- child: Text(
|
|
|
- '测量中',
|
|
|
- style: TextStyle(
|
|
|
- fontSize: 40,
|
|
|
- color: Colors.blue,
|
|
|
+ isConnect
|
|
|
+ ? const Expanded(
|
|
|
+ child: Row(children: [
|
|
|
+ Expanded(
|
|
|
+ child: Text(
|
|
|
+ '设备连接中',
|
|
|
+ style: TextStyle(
|
|
|
+ fontSize: 40,
|
|
|
+ color: Colors.blue,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
),
|
|
|
- ),
|
|
|
- ),
|
|
|
- CircularProgressIndicator(
|
|
|
- valueColor: AlwaysStoppedAnimation(
|
|
|
- Colors.blue,
|
|
|
- ),
|
|
|
- ),
|
|
|
- SizedBox(
|
|
|
- width: 20,
|
|
|
- ),
|
|
|
- ]),
|
|
|
- )
|
|
|
- : TextButton(
|
|
|
- onPressed: () {
|
|
|
-
|
|
|
- },
|
|
|
- child: Container(
|
|
|
- padding: const EdgeInsets.symmetric(horizontal: 30),
|
|
|
- decoration: const BoxDecoration(
|
|
|
- borderRadius: BorderRadius.all(
|
|
|
- Radius.circular(
|
|
|
- 30,
|
|
|
+ CircularProgressIndicator(
|
|
|
+ valueColor: AlwaysStoppedAnimation(
|
|
|
+ Colors.blue,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ SizedBox(
|
|
|
+ width: 20,
|
|
|
+ ),
|
|
|
+ ]),
|
|
|
+ )
|
|
|
+ : Expanded(
|
|
|
+ child: TextButton(
|
|
|
+ onPressed: () async {
|
|
|
+
|
|
|
+ await connect();
|
|
|
+ worker.connectFailEvent.addListener(_onConnectFail);
|
|
|
+ worker.connectSuccessEvent
|
|
|
+ .addListener(_onConnectSuccess);
|
|
|
+
|
|
|
+
|
|
|
+ Future.delayed(const Duration(milliseconds: 8000),
|
|
|
+ () {
|
|
|
+ if (!connectSuccessState) {
|
|
|
+ connectFailState = true;
|
|
|
+ Store.app.busy = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ child: Container(
|
|
|
+ padding: const EdgeInsets.symmetric(horizontal: 30),
|
|
|
+ decoration: const BoxDecoration(
|
|
|
+ borderRadius: BorderRadius.all(
|
|
|
+ Radius.circular(
|
|
|
+ 30,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ color: Colors.blue,
|
|
|
+ ),
|
|
|
+ child: const Text(
|
|
|
+ '测量',
|
|
|
+ style: TextStyle(fontSize: 40, color: Colors.white),
|
|
|
+ ),
|
|
|
),
|
|
|
),
|
|
|
- color: Colors.blue,
|
|
|
),
|
|
|
- child: const Text(
|
|
|
- '测量',
|
|
|
- style: TextStyle(fontSize: 40, color: Colors.white),
|
|
|
- ),
|
|
|
- ),
|
|
|
- ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
],
|
|
|
),
|
|
|
- showCancel: false,
|
|
|
+ showCancel: true,
|
|
|
+ onConfirm: () {
|
|
|
+ Get.back(result: specialInputController.text);
|
|
|
+ },
|
|
|
);
|
|
|
}
|
|
|
}
|