更新
This commit is contained in:
@@ -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: [
|
||||
|
||||
Reference in New Issue
Block a user