更新设备校准

This commit is contained in:
wyf
2025-06-03 09:00:01 +08:00
parent 7a816922fa
commit eed93bc6a4
30 changed files with 4257 additions and 1259 deletions

View File

@@ -79,7 +79,15 @@ class _EPageState extends State<BindDeviceSuccess> {
left: 40.rpx,
child: ClickableContainer(
onTap: () {
Get.offAllNamed("/mianPageBottomChange");
if (blueteethBindController.returnPage == 0) {
Get.until((route) =>
Get.currentRoute == "/mianPageBottomChange");
} else {
// Get.offNamed("/bodyDevice");
// Get.offNamedUntil(page, predicate);
Get.until(
(route) => Get.currentRoute == "/bodyDevice");
}
},
backgroundColor: Colors.transparent,
highlightColor: Colors
@@ -271,9 +279,13 @@ class _EPageState extends State<BindDeviceSuccess> {
BlueteethBindController blueteethBindController =
Get.find();
if (blueteethBindController.returnPage == 0) {
Get.offAllNamed("/mianPageBottomChange");
Get.until((route) =>
Get.currentRoute == "/mianPageBottomChange");
} else {
Get.offAllNamed("/bodyDevice");
// Get.offNamed("/bodyDevice");
// Get.offNamedUntil(page, predicate);
Get.until(
(route) => Get.currentRoute == "/bodyDevice");
}
},
colors: [

View File

@@ -123,6 +123,8 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
var bluetoothState = await FlutterBluePlus.isOn;
if (!bluetoothState && !_isDialogShowing) {
_isDialogShowing = true;
blueteethBindController.model.blelist = [];
blueteethBindController.updateAll();
await _showBluetoothNotEnabledDialog();
_isDialogShowing = false;
return;
@@ -134,68 +136,7 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
});
await FlutterBluePlus.startScan(timeout: Duration(seconds: 10));
// await FlutterBluePlus.startScan(timeout: Duration(minutes: 30));
// _scanSubscription = FlutterBluePlus.scanResults.listen((results) {
// if (!mounted) return; // 确保页面未销毁
// final signalThreshold = blueteethBindController.model.singal!;
// final filteredResults = results
// .where((r) =>
// r.rssi > signalThreshold &&
// r.advertisementData.localName == "AITH-V2" &&
// r.advertisementData.manufacturerData.containsKey(0xFFED))
// .toList();
// // 解析数据
// final parsedDeviceList = <BleDeviceData>[];
// for (var r in filteredResults) {
// try {
// List<int> rawData = r.advertisementData.manufacturerData[0xFFED]!;
// BleDeviceData deviceData = parseBleData(rawData);
// deviceData.name = r.advertisementData.advName;
// deviceData.rssi = r.rssi;
// deviceData.mac = deviceData.deviceId.replaceAll(':', '');
// parsedDeviceList.add(deviceData);
// if (deviceData.mac!.toLowerCase() == 'b43a45c3dfa0') {
// print('匹配设备数据: ${deviceData.mac}-->sn:${deviceData.sn}');
// }
// } catch (e) {
// print("设备数据解析失败: $e");
// }
// }
// // 使用一个临时变量 lastDeviceList 来比较是否有变化
// setState(() {
// bool hasChanges = false;
// // 如果 devicelist 长度不同或内容有差异,认为有变化
// if (blueteethBindController.model.devicelist?.length !=
// parsedDeviceList.length) {
// hasChanges = true;
// } else {
// // 深度比较每个设备的属性(比如 mac, rssi
// for (int i = 0;
// i < blueteethBindController.model.devicelist!.length;
// i++) {
// if (blueteethBindController.model.devicelist![i].mac !=
// parsedDeviceList[i].mac ||
// blueteethBindController.model.devicelist![i].rssi !=
// parsedDeviceList[i].rssi) {
// hasChanges = true;
// break;
// }
// }
// }
// // 如果有变化,更新 devicelist 和 blelist
// if (hasChanges) {
// blueteethBindController.model.devicelist = parsedDeviceList;
// blueteethBindController.model.blelist = filteredResults;
// // blueteethBindController.updateDeviceStatus();
// }
// });
// });
_scanSubscription = FlutterBluePlus.scanResults.listen((results) {
if (!mounted) return;
@@ -322,6 +263,7 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
_scanSubscription?.cancel(); // 取消扫描订阅
connectTimer?.cancel(); // 取消连接定时器
blueteethBindController.stopStatusPolling(); // 停止状态轮询
blueteethBindController.model.blelist = [];
super.dispose();
}
@@ -753,19 +695,6 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
),
],
));
// await showDialog(
// context: context,
// builder: (_) => AlertDialog(
// title: Text("蓝牙未开启"),
// content: Text("请先打开蓝牙再进行设备扫描"),
// actions: [
// TextButton(
// onPressed: () => Navigator.of(context).pop(),
// child: Text("知道了"),
// ),
// ],
// ),
// );
}
}

View File

@@ -0,0 +1,80 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
class CalibrationProgressWidget extends StatelessWidget {
final ValueNotifier<double> progressNotifier;
final ValueNotifier<bool> failureNotifier;
const CalibrationProgressWidget({
Key? key,
required this.progressNotifier,
required this.failureNotifier,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<double>(
valueListenable: progressNotifier,
builder: (context, progress, _) {
return ValueListenableBuilder<bool>(
valueListenable: failureNotifier,
builder: (context, isFailure, __) {
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
isFailure ? '失败'.tr : '${progress.toStringAsFixed(0)}%',
style: TextStyle(
fontSize: 26.rpx,
color: isFailure
? Colors.red
: themeController.currentColor.sc3,
),
),
SizedBox(height: 40.rpx),
Stack(
children: [
Container(
width: double.infinity,
height: 21.rpx,
decoration: BoxDecoration(
color: stringToColor("#D9D9D9"),
borderRadius: BorderRadius.circular(
AppConstants().button_container_radius,
),
),
),
Container(
width: progress / 100 *
MediaQuery.of(context).size.width *
0.8,
height: 21.rpx,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: isFailure
? [themeController.currentColor.sc9]
: [
themeController.currentColor.sc2,
themeController.currentColor.sc2,
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
borderRadius: BorderRadius.circular(
AppConstants().button_container_radius,
),
),
),
],
),
],
);
},
);
},
);
}
}

View File

@@ -66,7 +66,7 @@ class _SingleBlueteethDeviceCompoentWidgetState
showConfirmDialog(
context, Container(), "其他设备正在绑定中,是否终止其他设备绑定?".tr,
onConfirm: () {
blueteethBindController.currentDeviceMac = null;
blueteethBindController.currentDeviceMac.value = "";
blueteethBindController.updateAll();
}, onCancel: () {});
}
@@ -76,7 +76,9 @@ class _SingleBlueteethDeviceCompoentWidgetState
}
if (device.bind == true) {
showHaveBindDialog(context);
await showHaveBindDialog(context);
blueteethBindController.currentDeviceMac.value = "";
blueteethBindController.updateAll();
} else {
showConfirmDialog(
context,
@@ -87,52 +89,14 @@ class _SingleBlueteethDeviceCompoentWidgetState
await blueteethBindController.bindDeviceAndMAC(device);
TopSlideNotification.show(context, text: response.msg!);
if (response.code == HttpStatusCodes.ok) {
// showLoadingDialog(context); // 显示 loading
// Get.toNamed("/personPage");
Get.toNamed("/wifiPage");
THapp bledevice = THapp(device: widget.bleDevice.device);
blueteethBindController.currentDevice = bledevice;
// await bledevice.device.connect();
// var res2 = bledevice.isConnected;
// if (res2) {
// // Navigator.pop(context);
// TopSlideNotification.show(
// context,
// text: "蓝牙绑定.连接成功".tr,
// textColor: themeController.currentColor.sc2,
// );
// blueteethBindController.currentDevice = bledevice;
// if (lisObj != null) {
// lisObj!.cancel();
// }
// var aa;
// lisObj = blueteethBindController.currentDevice!.statusStream
// .listen((onData) async {
// if (onData.status == BleEventType.recvLineLog) {
// final line = onData.val;
// print("[bleee]:" + line);
// }
// if (onData.status == BleEventType.ready) {
// aa = await getDeviceNetVersion(
// blueteethBindController.currentDevice!, 1);
// if (aa == "4g") {
// Get.toNamed("/calibrationPage", arguments: 1);
// } else {
// Get.toNamed("/wifiPage");
// }
// }
// });
// } else {
// // Navigator.pop(context);
// TopSlideNotification.show(
// context,
// text: "蓝牙绑定.连接失败".tr,
// textColor: themeController.currentColor.sc9,
// );
// }
// blueteethBindController.currentDeviceMac.value = "";
} else {
blueteethBindController.currentDeviceMac = null;
blueteethBindController.currentDeviceMac.value = "";
blueteethBindController.updateAll();
TopSlideNotification.show(
context,
@@ -143,7 +107,7 @@ class _SingleBlueteethDeviceCompoentWidgetState
},
onCancel: () {
print('用户点击了取消');
blueteethBindController.currentDeviceMac?.value = "";
blueteethBindController.currentDeviceMac.value = "";
blueteethBindController.updateAll();
},
);
@@ -179,7 +143,8 @@ class _SingleBlueteethDeviceCompoentWidgetState
),
),
Obx(() {
if (blueteethBindController.currentDeviceMac == device.mac) {
if (blueteethBindController.currentDeviceMac.value ==
device.mac) {
return SizedBox(
width: 24.rpx,
height: 24.rpx,

View File

@@ -133,10 +133,10 @@ void showBindDoubleDialog(BuildContext context, List<BleDeviceData> devices) {
);
}
void showHaveBindDialog(BuildContext context) {
Future<void> showHaveBindDialog(BuildContext context) async {
ThemeController themeController = Get.find();
showDialog(
return showDialog(
context: context,
barrierDismissible: true,
barrierColor: Colors.black.withOpacity(0.5),
@@ -207,7 +207,7 @@ void showHaveBindDialog(BuildContext context) {
child: CustomCard(
borderRadius: AppConstants().button_container_radius,
onTap: () {
Get.back();
Get.back(result: true);
},
colors: [
themeController.currentColor.sc1,
@@ -860,27 +860,24 @@ void showWifiDialog(
);
}
String showTipDialog(
Future<void> showTipDialog(
BuildContext context,
Widget widget, {
Color? backgroundColor, // 新增可选参数
}
// String title,
) {
Color? backgroundColor,
}) {
ThemeController themeController = Get.find();
BlueteethBindController blueteethBindController = Get.find();
showDialog(
return showDialog(
context: context,
barrierDismissible: true,
barrierColor: Colors.black.withOpacity(0.5), // 背景模糊色
barrierColor: Colors.black.withOpacity(0.5),
builder: (BuildContext context) {
return FrostedDialog(
blurSigma: 3.0,
child: Container(
decoration: BoxDecoration(
color:
backgroundColor ?? themeController.currentColor.sc17, // 使用默认颜色
color: backgroundColor ?? themeController.currentColor.sc17,
borderRadius: BorderRadius.circular(20.0),
),
padding: EdgeInsetsDirectional.fromSTEB(64.rpx, 0, 64.rpx, 0),
@@ -892,63 +889,20 @@ String showTipDialog(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// 标题
// Row(
// mainAxisAlignment: MainAxisAlignment.end,
// children: [
// ClickableContainer(
// backgroundColor: Colors.transparent, // 容器背景色
// highlightColor:
// themeController.currentColor.sc21, // 点击时的背景色
// padding: EdgeInsets.zero, // 这里去掉外部的 padding避免影响点击范围
// onTap: () {
// Get.back();
// },
// child: Padding(
// padding:
// EdgeInsetsDirectional.fromSTEB(0, 33.rpx, 0, 0.rpx),
// child: SvgPicture.asset(
// 'assets/img/icon/close.svg',
// width: 25.rpx,
// height: 25.rpx, // 如果 SVG 中没有固定颜色,使用 color 设置
// color: themeController.currentColor.sc3,
// ),
// ),
// ),
// ],
// ),
// Align(
// alignment: AlignmentDirectional(0, 0),
// child: Padding(
// padding: EdgeInsetsDirectional.fromSTEB(
// 0.rpx, 93.rpx, 0, 74.rpx),
// child: Text(
// title,
// style: FlutterFlowTheme.of(context).bodyMedium.override(
// fontFamily: 'Inter',
// fontSize: 30.rpx,
// letterSpacing: 0.0,
// color: themeController.currentColor.sc3,
// ),
// ),
// ),
// ),
Align(
alignment: AlignmentDirectional(0, 0),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
0.rpx, 93.rpx, 0, 74.rpx),
padding:
EdgeInsetsDirectional.fromSTEB(0.rpx, 93.rpx, 0, 74.rpx),
child: widget,
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(0, 19.rpx, 0, 60.rpx),
child: CustomCard(
borderRadius: AppConstants().button_container_radius,
onTap: () {
Get.back();
Get.back(); // 关闭对话框
},
colors: [
themeController.currentColor.sc1,
@@ -972,13 +926,12 @@ String showTipDialog(
.override(
color: themeController.currentColor.sc3,
fontFamily: 'Inter',
fontSize: AppConstants().normal_text_fontSize,
fontSize:
AppConstants().normal_text_fontSize,
letterSpacing: 0.0,
),
),
].divide(SizedBox(
width: 17.rpx,
)),
].divide(SizedBox(width: 17.rpx)),
),
),
),
@@ -990,5 +943,4 @@ String showTipDialog(
);
},
);
return "";
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,926 @@
import 'dart:async';
import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:vbvs_app/common/color/ServiceConstant.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/common/util/requestWithLog.dart';
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
import 'package:vbvs_app/component/tool/CustomCard.dart';
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
import 'package:vbvs_app/controller/device/blueteeth_bind_controller.dart';
import 'package:vbvs_app/controller/device/device_calibration_controller.dart';
import 'package:vbvs_app/pages/common/selectDialog.dart';
import 'package:vbvs_app/pages/device_bind/componnet/bind_dialog.dart';
class CalibrationPage extends StatefulWidget {
int? type; //1.绑定时 2.绑定后
CalibrationPage({super.key, required this.type});
@override
State<CalibrationPage> createState() => _CalibrationPageState();
}
class _CalibrationPageState extends State<CalibrationPage> {
DeviceCalibrationController deviceCalibrationController = Get.find();
BlueteethBindController blueteethBindController = Get.find();
bool exit = false;
@override
void initState() {
super.initState();
deviceCalibrationController.process.value = 0;
deviceCalibrationController.bed_calibration.value = 0;
deviceCalibrationController.position_calibration.value = 0;
blueteethBindController.cid!.value = "";
}
@override
void dispose() {
blueteethBindController.cid!.value = "";
super.dispose();
}
@override
Widget build(BuildContext context) {
return WillPopScope(
child: LayoutBuilder(
builder: (context, bodySize) => GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/img/bgNoImg.png'),
fit: BoxFit.fill,
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
backgroundColor: themeController.currentColor.sc17,
automaticallyImplyLeading: false,
iconTheme:
IconThemeData(color: themeController.currentColor.sc3),
titleSpacing: 0,
title: Container(
width: double.infinity,
height: 180.rpx,
child: Stack(
alignment: Alignment.center,
children: [
Text(
'设备校准'.tr,
style: TextStyle(
fontFamily: 'Readex Pro',
color: themeController.currentColor.sc3,
letterSpacing: 0,
fontSize: 30.rpx,
),
),
Positioned(
left: 0,
child: returnIconButtomAddCallback(() {
if (deviceCalibrationController.flag.value != 2) {
try {
showConfirmDialog(
context, Container(), "校准未完成提示".tr,
onConfirm: () async {
exit = true;
if (widget.type == 2) {
Get.back();
return;
}
await Get.toNamed("/personPage");
print("object");
deviceCalibrationController.process.value = 0;
deviceCalibrationController
.bed_calibration.value = 0;
deviceCalibrationController
.position_calibration.value = 0;
blueteethBindController.cid!.value = "";
}, onCancel: () {
exit = false;
});
} catch (e) {
print(e);
}
} else {
exit = true;
}
if (exit) {
Get.back();
}
}, enableBack: exit),
),
Positioned(
right: 20.rpx,
child: CustomCard(
borderRadius: 20.rpx,
onTap: () async {
if (deviceCalibrationController.flag.value != 2) {
showConfirmDialog(
context, Container(), "校准未完成提示".tr,
onConfirm: () async {
await Get.toNamed("/personPage");
print("object");
deviceCalibrationController.process.value = 0;
deviceCalibrationController
.bed_calibration.value = 0;
deviceCalibrationController
.position_calibration.value = 0;
blueteethBindController.cid!.value = "";
}, onCancel: () {});
} else {
await Get.toNamed("/personPage");
deviceCalibrationController.process.value = 0;
deviceCalibrationController
.bed_calibration.value = 0;
deviceCalibrationController
.position_calibration.value = 0;
blueteethBindController.cid!.value = "";
}
},
colors: [
themeController.currentColor.sc1,
themeController.currentColor.sc2,
],
child: Container(
width: 130.rpx,
height: 60.rpx,
alignment: Alignment.center,
padding: EdgeInsetsDirectional.fromSTEB(
16.rpx, 0, 16.rpx, 0),
child: Text(
'下一步'.tr,
style: TextStyle(
fontFamily: 'Inter Tight',
color: themeController.currentColor.sc3,
letterSpacing: 0.0,
),
),
),
),
),
],
),
),
actions: [],
centerTitle: false,
),
body: SafeArea(
top: true,
// child: Container(),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
30.rpx, 0.rpx, 30.rpx, 0.rpx),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
0.rpx, 30.rpx, 0, 0),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: themeController.currentColor.sc5,
borderRadius: BorderRadius.circular(16.rpx),
),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
10.rpx, 20.rpx, 34.rpx, 20.rpx),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
ClickableContainer(
backgroundColor: Colors.transparent,
highlightColor:
themeController.currentColor.sc21,
borderRadius: 0, // 可按需设置圆角
padding: EdgeInsets.symmetric(
vertical: 10.rpx), // 可自定义内边距
onTap: () {
// deviceCalibrationController.process.value = 0;
// deviceCalibrationController.updateAll();
},
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Obx(() {
return Visibility(
maintainState: true,
maintainAnimation: true,
maintainSize: true,
visible:
deviceCalibrationController
.process.value ==
0,
child: SvgPicture.asset(
'assets/img/icon/select_arrow.svg',
width: 17.rpx,
height: 17.rpx,
color: themeController
.currentColor.sc9,
),
);
}),
SizedBox(width: 8.rpx),
Text(
'离床校准'.tr,
style: TextStyle(
fontSize: 30.rpx,
letterSpacing: 0.0,
color: themeController
.currentColor.sc3,
),
),
],
),
Obx(() {
return Text(
deviceCalibrationController
.bed_calibration
.value ==
0
? '未完成'.tr
: "已完成".tr,
style: TextStyle(
fontSize: 26.rpx,
letterSpacing: 0.0,
color: deviceCalibrationController
.bed_calibration
.value ==
0
? themeController
.currentColor.sc3
: themeController
.currentColor.sc1,
),
);
}),
],
),
),
SizedBox(height: 41.rpx),
ClickableContainer(
backgroundColor: Colors.transparent,
highlightColor:
themeController.currentColor.sc21,
borderRadius: 0, // 可根据需要设为圆角
padding: EdgeInsets.symmetric(
vertical: 10.rpx), // 可根据需要调整上下内边距
onTap: () {
// deviceCalibrationController.process.value = 1;
// deviceCalibrationController.updateAll();
},
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Obx(() {
return Visibility(
maintainState: true,
maintainAnimation: true,
maintainSize: true,
visible:
deviceCalibrationController
.process.value ==
1,
child: SvgPicture.asset(
'assets/img/icon/select_arrow.svg',
width: 17.rpx,
height: 17.rpx,
color: themeController
.currentColor.sc9,
),
);
}),
SizedBox(width: 8.rpx),
Text(
'位置校准'.tr,
style: TextStyle(
fontSize: 30.rpx,
letterSpacing: 0.0,
color: themeController
.currentColor.sc3,
),
),
],
),
Obx(() {
return Text(
deviceCalibrationController
.position_calibration
.value ==
0
? '未完成'.tr
: "已完成".tr,
style: TextStyle(
fontSize: 26.rpx,
letterSpacing: 0.0,
color: deviceCalibrationController
.position_calibration
.value ==
0
? themeController
.currentColor.sc3
: themeController
.currentColor.sc1,
),
);
}),
],
),
),
],
),
),
),
),
Obx(() {
return Expanded(
child: SizedBox(
width: double.infinity,
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
100.rpx, 55.rpx, 100.rpx, 0),
child: Stack(
clipBehavior: Clip.none,
children: [
Container(
width: MediaQuery.sizeOf(context).width *
0.65,
height:
MediaQuery.sizeOf(context).height *
0.3,
child: Stack(
children: [
// Image.asset(
// deviceCalibrationController
// .bed_type.value ==
// 0
// ? "assets/img/single_pillow.png"
// : "assets/img/double_pillow.png",
// width: double.infinity,
// height: double.infinity,
// fit: BoxFit.contain,
// ),
Image.asset(
deviceCalibrationController
.process.value ==
1 &&
deviceCalibrationController
.position_calibration
.value ==
1
? (deviceCalibrationController
.bed_type.value ==
0
? "assets/img/single_person.png"
: "assets/img/double_person.png")
: (deviceCalibrationController
.bed_type.value ==
0
? "assets/img/single_pillow.png"
: "assets/img/double_pillow.png"),
width: double.infinity,
height: double.infinity,
fit: BoxFit.contain,
),
// 床头文字
Positioned(
top: 23.rpx,
left: (MediaQuery.sizeOf(context)
.width *
0.65) /
2 -
26.rpx,
child: Text(
'床头'.tr,
style: TextStyle(
fontSize: 26.rpx,
color: themeController
.currentColor.sc4,
),
),
),
],
),
),
Obx(() {
final double centerLeft =
(bodySize.maxWidth * 0.56) / 2;
if (deviceCalibrationController
.bed_type.value ==
0 &&
deviceCalibrationController
.process.value ==
1) {
//单人床位置校准
return Positioned(
top: -40.rpx,
left: centerLeft - 0.rpx,
child: Container(
width: bodySize.maxWidth * 0.087,
height: bodySize.maxHeight * 0.06,
constraints: BoxConstraints(
minWidth: 65.rpx,
minHeight: 76.rpx,
),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/img/tip_arrow.gif'),
fit: BoxFit.cover,
),
),
),
);
}
if (deviceCalibrationController
.bed_type.value ==
1 &&
deviceCalibrationController
.process.value ==
1) {
//双人人床位置校准
return Positioned(
top: -40.rpx,
left: (MediaQuery.sizeOf(context)
.width *
0.65) *
0.22 -
0.rpx,
child: Container(
width: bodySize.maxWidth * 0.087,
height: bodySize.maxHeight * 0.06,
constraints: BoxConstraints(
minWidth: 65.rpx,
minHeight: 76.rpx,
),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/img/tip_arrow.gif'),
fit: BoxFit.cover,
),
),
),
);
}
return Container();
}),
Positioned(
top: MediaQuery.sizeOf(context).height *
0.3 +
82.rpx,
left: 0,
right: 0,
child: Obx(() {
return Column(
children: [
Text(
(deviceCalibrationController
.process
.value ==
0 &&
deviceCalibrationController
.bed_calibration
.value ==
1) ||
(deviceCalibrationController
.process
.value ==
1 &&
deviceCalibrationController
.position_calibration
.value ==
1)
? '校准完成'.tr
: deviceCalibrationController
.process.value ==
0
? '离床校准提示'.tr
: '位置校准提示'.tr,
style: TextStyle(
fontSize: 38.rpx,
letterSpacing: 0.0,
color: ((deviceCalibrationController
.process
.value ==
0 &&
deviceCalibrationController
.bed_calibration
.value ==
1) ||
(deviceCalibrationController
.process
.value ==
1 &&
deviceCalibrationController
.position_calibration
.value ==
1))
? themeController
.currentColor.sc1
: themeController
.currentColor.sc9,
),
),
],
);
}),
),
],
),
),
),
);
}),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
100.rpx, 0.rpx, 100.rpx, 60.rpx),
child: CustomCard(
borderRadius:
AppConstants().button_container_radius, // 圆角半径
onTap: () async {
if (deviceCalibrationController.flag.value == 2) {
showConfirmDialog(
context, Container(), "校准已经完成,是否重新开始校准?",
onConfirm: () {
deviceCalibrationController.flag.value = 1;
BlueteethBindController
blueteethBindController = Get.find();
deviceCalibrationController.process.value = 0;
deviceCalibrationController
.bed_calibration.value = 0;
deviceCalibrationController
.position_calibration.value = 0;
blueteethBindController.cid!.value = "";
String serviceAddress =
"https://caibration.he-info.cn";
String calibrationApi =
ServiceConstant.start_calibration;
String progressApi =
ServiceConstant.calibration_process;
String queryUrl =
"$serviceAddress$calibrationApi";
final ValueNotifier<double> progressNotifier =
ValueNotifier<double>(0.0);
final ValueNotifier<bool> failureNotifier =
ValueNotifier<bool>(false);
Timer? pollingTimer;
Map<String, dynamic> data = {
"macA": blueteethBindController
.currentDeviceMac!.value,
};
// 是否是二次点击有cid表示进行第二阶段
bool isSecondStep = blueteethBindController
.cid?.value.isNotEmpty ??
false;
if (isSecondStep) {
data["id"] =
blueteethBindController.cid!.value;
}
// 发起校准请求
requestWithLog(
logTitle: "设备校准",
method: MyHttpMethod.post,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
if (!isSecondStep) {
// 保存第一次获取的 cid
String cid =
res.rawResponse.data['cid'];
blueteethBindController.cid!.value =
cid;
}
void requestCalibrationProgress() {
String cid =
blueteethBindController.cid!.value;
String progressUrl =
"$serviceAddress$progressApi?id=$cid";
requestWithLog(
logTitle: "设备校准进度",
method: MyHttpMethod.get,
queryUrl: progressUrl,
onSuccess: (res) {
final data = res.data;
double per =
(data['per'] ?? 0).toDouble();
int currStep =
data['currStep'] ?? -1;
bool status =
data['status'] ?? false;
String tips =
data['statusText'] ?? '';
deviceCalibrationController
.tips.value = tips;
progressNotifier.value = per;
if (!isSecondStep && per >= 20) {
progressNotifier.value = 100;
// 第一步完成:仅 per >= 100
pollingTimer?.cancel();
TopSlideNotification.show(context,
text: tips);
deviceCalibrationController
.process.value = 1;
deviceCalibrationController
.bed_calibration.value = 1;
deviceCalibrationController
.updateAll();
}
if (isSecondStep &&
per >= 100 &&
currStep == 5 &&
status == true) {
// 第二步完成per >= 100 && currStep == 5 && status == true
deviceCalibrationController
.flag.value = 2;
pollingTimer?.cancel();
TopSlideNotification.show(context,
text: "设备校准完成".tr);
// 可在这里执行校准完成后的业务逻辑更新
deviceCalibrationController
.bed_calibration.value = 1;
deviceCalibrationController
.position_calibration
.value = 1;
deviceCalibrationController
.process.value = 1;
deviceCalibrationController
.updateAll();
}
},
onFailure: (res) {
pollingTimer?.cancel();
failureNotifier.value = true;
TopSlideNotification.show(
context,
text: res.msg ?? "服务器.失败".tr,
textColor: themeController
.currentColor.sc9,
);
},
);
}
// 初始调用一次
requestCalibrationProgress();
// 开始轮询
pollingTimer = Timer.periodic(
Duration(seconds: 2), (_) {
requestCalibrationProgress();
});
// 显示进度弹窗
showProgressDialog(context,
progressNotifier, failureNotifier);
},
onFailure: (res) {
TopSlideNotification.show(
context,
text: res.msg ?? "服务器.失败".tr,
textColor:
themeController.currentColor.sc9,
);
},
);
}, onCancel: () {
return;
});
} else {
deviceCalibrationController.flag.value = 1;
BlueteethBindController
blueteethBindController = Get.find();
String serviceAddress =
"https://caibration.he-info.cn";
String calibrationApi =
ServiceConstant.start_calibration;
String progressApi =
ServiceConstant.calibration_process;
String queryUrl =
"$serviceAddress$calibrationApi";
final ValueNotifier<double> progressNotifier =
ValueNotifier<double>(0.0);
final ValueNotifier<bool> failureNotifier =
ValueNotifier<bool>(false);
Timer? pollingTimer;
Map<String, dynamic> data = {
"macA": blueteethBindController
.currentDeviceMac!.value,
};
// 是否是二次点击有cid表示进行第二阶段
bool isSecondStep = blueteethBindController
.cid?.value.isNotEmpty ??
false;
if (isSecondStep) {
data["id"] =
blueteethBindController.cid!.value;
}
// 发起校准请求
requestWithLog(
logTitle: "设备校准",
method: MyHttpMethod.post,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
if (!isSecondStep) {
// 保存第一次获取的 cid
String cid = res.rawResponse.data['cid'];
blueteethBindController.cid!.value = cid;
}
void requestCalibrationProgress() {
String cid =
blueteethBindController.cid!.value;
String progressUrl =
"$serviceAddress$progressApi?id=$cid";
requestWithLog(
logTitle: "设备校准进度",
method: MyHttpMethod.get,
queryUrl: progressUrl,
onSuccess: (res) {
final data = res.data;
double per =
(data['per'] ?? 0).toDouble();
int currStep = data['currStep'] ?? -1;
bool status = data['status'] ?? false;
String tips =
data['statusText'] ?? '';
deviceCalibrationController
.tips.value = tips;
progressNotifier.value = per;
if (!isSecondStep && per >= 20) {
progressNotifier.value = 100;
// 第一步完成:仅 per >= 100
pollingTimer?.cancel();
TopSlideNotification.show(context,
text: tips);
deviceCalibrationController
.process.value = 1;
deviceCalibrationController
.bed_calibration.value = 1;
deviceCalibrationController
.updateAll();
}
if (isSecondStep &&
per >= 100 &&
currStep == 5 &&
status == true) {
// 第二步完成per >= 100 && currStep == 5 && status == true
pollingTimer?.cancel();
TopSlideNotification.show(context,
text: "设备校准完成".tr);
// 可在这里执行校准完成后的业务逻辑更新
deviceCalibrationController
.bed_calibration.value = 1;
deviceCalibrationController
.position_calibration.value = 1;
deviceCalibrationController
.process.value = 1;
deviceCalibrationController
.flag.value = 2;
deviceCalibrationController
.updateAll();
}
},
onFailure: (res) {
pollingTimer?.cancel();
failureNotifier.value = true;
TopSlideNotification.show(
context,
text: res.msg ?? "服务器.失败".tr,
textColor: themeController
.currentColor.sc9,
);
},
);
}
// 初始调用一次
requestCalibrationProgress();
// 开始轮询
pollingTimer = Timer.periodic(
Duration(seconds: 2), (_) {
requestCalibrationProgress();
});
// 显示进度弹窗
showProgressDialog(context,
progressNotifier, failureNotifier);
},
onFailure: (res) {
TopSlideNotification.show(
context,
text: res.msg ?? "服务器.失败".tr,
textColor:
themeController.currentColor.sc9,
);
},
);
}
},
colors: [
themeController.currentColor.sc1,
themeController.currentColor.sc2,
],
child: Container(
width: bodySize.maxWidth,
height: MediaQuery.sizeOf(context).height * 0.055,
constraints: BoxConstraints(
minWidth: 500.rpx,
minHeight: 90.rpx,
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'开始校准'.tr,
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
//todo 颜色
color:
themeController.currentColor.sc3,
fontFamily: 'Inter',
fontSize: AppConstants()
.normal_text_fontSize,
letterSpacing: 0.0,
),
),
].divide(SizedBox(
width: 17.rpx,
)),
),
),
),
),
],
),
),
),
),
),
),
),
onWillPop: () async {
bool exit = false;
if (deviceCalibrationController.flag.value != 2) {
showConfirmDialog(context, Container(), "校准未完成提示".tr,
onConfirm: () async {
exit = true;
// await Get.toNamed("/personPage");
// print("object");
deviceCalibrationController.process.value = 0;
deviceCalibrationController.bed_calibration.value = 0;
deviceCalibrationController.position_calibration.value = 0;
blueteethBindController.cid!.value = "";
}, onCancel: () {
exit = false;
});
} else {
exit = true;
}
return exit;
});
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -23,7 +23,7 @@ import 'package:vbvs_app/pages/device_bind/blueteeth_device_page.dart';
import 'package:vbvs_app/pages/device_bind/componnet/bind_dialog.dart';
class WifiPage extends StatefulWidget {
var type;
var type; //为空,首次绑定 不为空,从设备列表进入
WifiPage({super.key, required this.type});
@override
@@ -41,88 +41,75 @@ class _WifiPageState extends State<WifiPage> {
@override
void initState() {
super.initState();
blueteethBindController.netType.value = 0;
blueteethBindController.connectStatus.value = 0;
blueteethBindController.wifiList = [].obs;
blueteethBindController.wifiStatus = 0.obs;
blueteethBindController.connect_wifi.value = {};
blueteethBindController.selectWifi.value = {};
if (widget.type != null) {
blueteethBindController.wifiStatus.value =
widget.type['status']['status'];
}
if (widget.type == null) {
THapp bledevice = blueteethBindController.currentDevice!;
bledevice.device.connect().then((Value) {
var res2 = bledevice.isConnected;
if (res2) {
// WidgetsBinding.instance.addPostFrameCallback((_) {
// TopSlideNotification.show(
// context,
// text: "蓝牙绑定.连接成功".tr,
// textColor: themeController.currentColor.sc2,
// );
// });
blueteethBindController.blueConnectFlag.value = 2;
blueteethBindController.currentDevice = bledevice;
if (lisObj != null) {
lisObj!.cancel();
THapp bledevice = blueteethBindController.currentDevice!;
bledevice.device.connect().then((Value) {
var res2 = bledevice.isConnected;
if (res2) {
blueteethBindController.blueConnectFlag.value = 2;
blueteethBindController.currentDevice = bledevice;
if (lisObj != null) {
lisObj!.cancel();
}
var aa;
lisObj = blueteethBindController.currentDevice!.statusStream
.listen((onData) async {
if (onData.status == BleEventType.recvLineLog) {
final line = onData.val;
print("[bleee]:" + line);
}
var aa;
lisObj = blueteethBindController.currentDevice!.statusStream
.listen((onData) async {
if (onData.status == BleEventType.recvLineLog) {
final line = onData.val;
print("[bleee]:" + line);
}
if (onData.status == BleEventType.ready) {
aa = await getDeviceNetVersion(
blueteethBindController.currentDevice!, 10);
if (aa == "4g") {
if (onData.status == BleEventType.ready) {
aa = await getDeviceNetVersion(
blueteethBindController.currentDevice!, 2);
if (aa == "4g") {
TopSlideNotification.show(
context,
text: "4g设备配置wifi提示".tr,
textColor: themeController.currentColor.sc2,
);
blueteethBindController.netType.value = 2;
blueteethBindController.connectStatus.value = 1;
blueteethBindController.updateAll();
Future.delayed(const Duration(seconds: 1), () {
Get.toNamed("/calibrationPage", arguments: 1);
});
} else if (aa == 'unknown') {
// TopSlideNotification.show(
// context,
// text: "获取设备网络类型失败".tr,
// textColor: themeController.currentColor.sc9,
// );
blueteethBindController.netType.value = 3;
blueteethBindController.updateAll();
WidgetsBinding.instance.addPostFrameCallback((_) {
TopSlideNotification.show(
context,
text: "4g设备配置wifi提示".tr,
textColor: themeController.currentColor.sc2,
text: "获取设备网络类型失败".tr,
textColor: themeController.currentColor.sc9,
);
blueteethBindController.connectStatus.value = 1;
blueteethBindController.updateAll();
Future.delayed(const Duration(seconds: 1), () {
Get.toNamed("/calibrationPage", arguments: 1);
});
} else if (aa == 'unknown') {
// TopSlideNotification.show(
// context,
// text: "获取设备网络类型失败".tr,
// textColor: themeController.currentColor.sc9,
// );
WidgetsBinding.instance.addPostFrameCallback((_) {
TopSlideNotification.show(
context,
text: "获取设备网络类型失败".tr,
textColor: themeController.currentColor.sc9,
);
});
} else {
await initWifiStatusAndWifiList();
}
});
} else {
blueteethBindController.netType.value = 1;
blueteethBindController.updateAll();
await initWifiStatusAndWifiList();
}
});
} else {
WidgetsBinding.instance.addPostFrameCallback((_) {
TopSlideNotification.show(
context,
text: "连接失败".tr,
textColor: themeController.currentColor.sc9,
);
});
}
});
} else {
blueteethBindController.blueConnectFlag.value = 0;
blueteethBindController.updateAll();
dealWifi(widget.type['mac']).then((aa) {
print("object");
});
}
}
});
} else {
WidgetsBinding.instance.addPostFrameCallback((_) {
TopSlideNotification.show(
context,
text: "连接失败".tr,
textColor: themeController.currentColor.sc9,
);
});
}
});
}
@override
@@ -180,36 +167,21 @@ class _WifiPageState extends State<WifiPage> {
),
if (widget.type == null)
Obx(() {
if (blueteethBindController.netType.value == 0) {
return SizedBox(
width: 24.rpx,
height: 24.rpx,
child: CircularProgressIndicator(
strokeWidth: 1,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white),
),
);
}
if (blueteethBindController.connectStatus.value ==
0) {
return SizedBox(
width: 24.rpx,
height: 24.rpx,
child: CircularProgressIndicator(
strokeWidth: 1,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white),
),
);
}
return Container();
}),
if (widget.type != null)
Obx(() {
if (blueteethBindController.blueConnectFlag.value ==
0) {
return SizedBox(
width: 24.rpx,
height: 24.rpx,
child: CircularProgressIndicator(
strokeWidth: 1,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white),
),
);
}
if (blueteethBindController.connectStatus.value ==
0&&blueteethBindController.blueConnectFlag.value ==0) {
0 &&
blueteethBindController.netType.value != 0) {
return SizedBox(
width: 24.rpx,
height: 24.rpx,
@@ -222,6 +194,7 @@ class _WifiPageState extends State<WifiPage> {
}
return Container();
}),
],
),
@@ -230,35 +203,35 @@ class _WifiPageState extends State<WifiPage> {
left: 0,
child: returnIconButtom,
),
if (widget.type == null)
Positioned(
right: 20.rpx,
child: CustomCard(
borderRadius: 20.rpx,
onTap: () async {
// if (blueteethBindController.wifiStatus.value != 1) {
// TopSlideNotification.show(
// context,
// text: "wifi页.需配网".tr,
// textColor: themeController.currentColor.sc9,
// );
// } else {
// Get.toNamed("/calibrationPage", arguments: 1);
// }
Get.toNamed("/calibrationPage", arguments: 1);
if (blueteethBindController.wifiStatus.value != 1) {
showConfirmDialog(
context, Container(), "未配置网络提示".tr,
onConfirm: () {
Get.toNamed("/calibrationPage", arguments: 1);
}, onCancel: () {});
} else {
Get.toNamed("/calibrationPage", arguments: 1);
}
},
colors: [
themeController.currentColor.sc1,
themeController.currentColor.sc2,
],
child: Container(
width: 100.rpx,
width: 130.rpx,
height: 60.rpx,
alignment: Alignment.center,
padding: EdgeInsetsDirectional.fromSTEB(
16.rpx, 0, 16.rpx, 0),
child: Text(
'wifi页.跳过'.tr,
'下一步'.tr,
style: FlutterFlowTheme.of(context)
.titleSmall
.override(
@@ -270,6 +243,7 @@ class _WifiPageState extends State<WifiPage> {
),
),
),
],
),
),
@@ -749,31 +723,71 @@ class _WifiPageState extends State<WifiPage> {
horizontal: 20.rpx, vertical: 10.rpx),
borderRadius: 20.rpx,
onTap: () async {
if ((blueteethBindController
.blueConnectFlag ==
0 ||
blueteethBindController
.blueConnectFlag ==
1) &&
widget.type != null) {
blueteethBindController
.blueConnectFlag.value = 0;
dealWifi(widget.type['mac']).then((aa) {
print("object");
});
return;
}
blueteethBindController
.connectStatus.value = 0;
blueteethBindController.updateAll();
print("点击刷新");
await initWifiList();
TopSlideNotification.show(
context,
text: "获取wifi列表成功".tr,
textColor:
themeController.currentColor.sc2,
);
if (blueteethBindController
.netType.value ==
0) {
return;
}
if (blueteethBindController
.netType.value ==
3) {
var aa = await getDeviceNetVersion(
blueteethBindController
.currentDevice!,
0);
if (aa == "4g") {
TopSlideNotification.show(
context,
text: "4g设备配置wifi提示".tr,
textColor: themeController
.currentColor.sc2,
);
blueteethBindController
.netType.value = 2;
blueteethBindController
.connectStatus.value = 1;
blueteethBindController.updateAll();
Future.delayed(
const Duration(seconds: 1), () {
Get.toNamed("/calibrationPage",
arguments: 1);
});
} else if (aa == 'unknown') {
// TopSlideNotification.show(
// context,
// text: "获取设备网络类型失败".tr,
// textColor: themeController.currentColor.sc9,
// );
blueteethBindController
.netType.value = 3;
blueteethBindController.updateAll();
WidgetsBinding.instance
.addPostFrameCallback((_) {
TopSlideNotification.show(
context,
text: "获取设备网络类型失败".tr,
textColor: themeController
.currentColor.sc9,
);
});
} else {
blueteethBindController
.netType.value = 1;
blueteethBindController.updateAll();
await initWifiStatusAndWifiList();
}
}
// await initWifiList();
// TopSlideNotification.show(
// context,
// text: "获取wifi列表成功".tr,
// textColor:
// themeController.currentColor.sc2,
// );
},
child: Row(
mainAxisSize: MainAxisSize.min,
@@ -832,6 +846,8 @@ class _WifiPageState extends State<WifiPage> {
if (aa != null && aa is Map) {
wifiStatus = true;
blueteethBindController.connect_wifi.value = aa;
} else {
wifiStatus = false;
}
blueteethBindController.wifiStatus.value = wifiStatus == true ? 1 : 0;
List wifiList = [];
@@ -982,9 +998,6 @@ class _WifiPageState extends State<WifiPage> {
}
Future<void> dealWifi(String mac) async {
// bodyDeviceController.wifiMac = mac;
// Get.toNamed("/wifiPage", arguments: 2);
// return;
final blueteethBindController = Get.find<BlueteethBindController>();
final themeController = Get.find<ThemeController>();
@@ -1072,7 +1085,7 @@ class _WifiPageState extends State<WifiPage> {
}
if (onData.status == BleEventType.ready) {
aa = await getDeviceNetVersion(
blueteethBindController.currentDevice!, 1);
blueteethBindController.currentDevice!, 0);
if (aa == "4g") {
// TopSlideNotification.show(
// Get.context!,
@@ -1088,14 +1101,21 @@ class _WifiPageState extends State<WifiPage> {
Get.back();
});
return;
} else if (aa == 'unknown') {
blueteethBindController.netType.value = 3;
blueteethBindController.updateAll();
WidgetsBinding.instance.addPostFrameCallback((_) {
TopSlideNotification.show(
context,
text: "获取设备网络类型失败".tr,
textColor: themeController.currentColor.sc9,
);
});
} else {
// Get.toNamed("/wifiPage", arguments: 2);
await initWifiStatusAndWifiList();
}
}
});
// Get.toNamed("/wifiPage", arguments: {bledevice});
} else {
// Navigator.pop(context);
TopSlideNotification.show(

File diff suppressed because it is too large Load Diff