This commit is contained in:
wyf
2025-05-20 14:00:44 +08:00
parent 75ddfca402
commit 0a8cffa4c6
48 changed files with 5221 additions and 1733 deletions

View File

@@ -8,6 +8,7 @@ import 'package:vbvs_app/common/util/DailyLogUtils.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
import 'package:vbvs_app/component/tool/cmd.dart';
import 'package:vbvs_app/controller/device/blueteeth_bind_controller.dart';
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
import 'package:vbvs_app/model/BleDeviceData.dart';
@@ -32,6 +33,8 @@ class _SingleBlueteethDeviceCompoentWidgetState
extends State<SingleBlueteethDeviceCompoentWidget> {
ThemeController themeController = Get.find();
BlueteethBindController blueteethBindController = Get.find();
var lisObj;
@override
Widget build(BuildContext context) {
List<int> rawData =
@@ -41,12 +44,11 @@ class _SingleBlueteethDeviceCompoentWidgetState
deviceData.rssi = widget.bleDevice.rssi;
deviceData.mac = deviceData.deviceId.replaceAll(':', '');
BleDeviceData device = deviceData;
blueteethBindController.currentDeviceMac = device.mac;
// blueteethBindController.currentDeviceMac = device.mac;
device = blueteethBindController.model.betDevicelist!.firstWhere(
(d) => d.mac == device.mac,
orElse: () => device,
);
return ClickableContainer(
backgroundColor: themeController.currentColor.sc5,
highlightColor: themeController.currentColor.sc21,
@@ -54,9 +56,25 @@ class _SingleBlueteethDeviceCompoentWidgetState
padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 36.rpx, 0, 52.rpx),
onTap: () async {
try {
//1.先判斷当前是否有别的设备处于连接中,没有处于连接,判断是否绑定;
//2.如果没有绑定,直接连接;如果绑定,弹出提示框,提示是否解绑;
if (blueteethBindController.currentDeviceMac?.value != null &&
blueteethBindController.currentDeviceMac!.value.isNotEmpty) {
if (blueteethBindController.currentDeviceMac?.value != device.mac) {
showConfirmDialog(
context, Container(), "其他设备正在绑定中,是否终止其他设备绑定?".tr,
onConfirm: () {
blueteethBindController.currentDeviceMac = null;
blueteethBindController.updateAll();
}, onCancel: () {});
}
} else {
blueteethBindController.currentDeviceMac?.value = device.mac!;
blueteethBindController.updateAll();
}
if (device.bind == true) {
showHaveBindDialog(context);
// showBindDoubleDialog(context, []);
} else {
showConfirmDialog(
context,
@@ -67,29 +85,52 @@ class _SingleBlueteethDeviceCompoentWidgetState
await blueteethBindController.bindDeviceAndMAC(device);
TopSlideNotification.show(context, text: response.msg!);
if (response.code == HttpStatusCodes.ok) {
showLoadingDialog(context); // 显示 loading
// showLoadingDialog(context); // 显示 loading
Get.toNamed("/personPage");
THapp bledevice = THapp(device: widget.bleDevice.device);
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;
// Get.toNamed("/wifiPage", arguments: {bledevice});
Get.toNamed("/wifiPage");
} else {
Navigator.pop(context);
TopSlideNotification.show(
context,
text: "蓝牙绑定.连接失败".tr,
textColor: themeController.currentColor.sc9,
);
}
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,
// );
// }
} else {
blueteethBindController.currentDeviceMac = null;
blueteethBindController.updateAll();
TopSlideNotification.show(
context,
text: response.msg ?? "蓝牙绑定.连接异常".tr,
@@ -99,10 +140,10 @@ class _SingleBlueteethDeviceCompoentWidgetState
},
onCancel: () {
print('用户点击了取消');
// 执行取消后的处理逻辑
blueteethBindController.currentDeviceMac?.value = "";
blueteethBindController.updateAll();
},
);
}
} catch (e) {
Navigator.pop(context);
@@ -119,14 +160,36 @@ class _SingleBlueteethDeviceCompoentWidgetState
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Text(
device.name ?? '蓝牙绑定.默认设备名称'.tr,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 30.rpx,
letterSpacing: 0.0,
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0.rpx, 0.rpx, 30.rpx, 0.rpx),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
device.name ?? '蓝牙绑定.默认设备名称'.tr,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFFF6FAFD),
fontSize: 30.rpx,
letterSpacing: 0.0,
),
),
Obx(() {
if (blueteethBindController.currentDeviceMac == device.mac) {
return SizedBox(
width: 24.rpx,
height: 24.rpx,
child: CircularProgressIndicator(
strokeWidth: 1,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
);
}
return Container();
}),
],
),
),
Row(
children: [

View File

@@ -426,7 +426,7 @@ void showConfirmDialog(
color: themeController.currentColor.sc17,
borderRadius: BorderRadius.circular(20.0),
),
padding: EdgeInsetsDirectional.fromSTEB(64.rpx, 0, 64.rpx, 0),
padding: EdgeInsetsDirectional.fromSTEB(31.rpx, 0, 31.rpx, 0),
child: Container(
width: double.infinity,
constraints: BoxConstraints(
@@ -446,10 +446,13 @@ void showConfirmDialog(
padding: EdgeInsets.zero, // 这里去掉外部的 padding避免影响点击范围
onTap: () {
Get.back();
onCancel();
},
child: Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0, 33.rpx, 0, 0.rpx),
// padding:
// EdgeInsetsDirectional.fromSTEB(0, 33.rpx, 0, 0.rpx),
padding: EdgeInsetsDirectional.fromSTEB(
33.rpx, 33.rpx, 33.rpx, 33.rpx),
child: SvgPicture.asset(
'assets/img/icon/close.svg',
width: 25.rpx,
@@ -463,8 +466,8 @@ void showConfirmDialog(
Align(
alignment: AlignmentDirectional(0, 0),
child: Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0.rpx, 93.rpx, 0, 0),
padding: EdgeInsetsDirectional.fromSTEB(
33.rpx, 60.rpx, 33.rpx, 33.rpx),
child: Text(
title,
style: FlutterFlowTheme.of(context).bodyMedium.override(
@@ -476,18 +479,22 @@ void showConfirmDialog(
),
),
),
widget,
Padding(
padding: EdgeInsetsDirectional.fromSTEB(0, 58.rpx, 0, 60.rpx),
padding: EdgeInsetsDirectional.fromSTEB(
33.rpx, 0.rpx, 33.rpx, 0.rpx),
child: widget,
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
33.rpx, 58.rpx, 33.rpx, 60.rpx),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomCard(
borderRadius: AppConstants().button_container_radius,
onTap: () async {
onConfirm();
// await Future.delayed(Duration(milliseconds: 300));
Get.back();
onCancel();
},
colors: [
themeController.currentColor.sc1,
@@ -505,7 +512,7 @@ void showConfirmDialog(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"蓝牙绑定.".tr,
"蓝牙绑定.".tr,
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
@@ -523,8 +530,9 @@ void showConfirmDialog(
CustomCard(
borderRadius: AppConstants().button_container_radius,
onTap: () {
onConfirm();
// await Future.delayed(Duration(milliseconds: 300));
Get.back();
onCancel();
},
colors: [
themeController.currentColor.sc1,
@@ -542,7 +550,7 @@ void showConfirmDialog(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"蓝牙绑定.".tr,
"蓝牙绑定.".tr,
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
@@ -660,8 +668,8 @@ void showWifiDialog(
textColor: themeController.currentColor.sc9,
);
} else {
Get.back();
onConfirm();
Get.back();
}
},
colors: [
@@ -788,7 +796,6 @@ void showTipDialog(
child: widget,
),
),
// widget,
Padding(
padding: EdgeInsetsDirectional.fromSTEB(0, 19.rpx, 0, 60.rpx),