更新
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:flutterflow_ui/flutterflow_ui.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/component/tool/ClickableContainer.dart';
|
||||
import 'package:vbvs_app/component/tool/CustomCard.dart';
|
||||
import 'package:vbvs_app/controller/device/blueteeth_bind_controller.dart';
|
||||
import 'package:vbvs_app/controller/device/body_device_controller.dart';
|
||||
@@ -71,9 +72,28 @@ class _EPageState extends State<BindDeviceSuccess> {
|
||||
),
|
||||
|
||||
/// 左边返回按钮
|
||||
// Positioned(
|
||||
// left: 0,
|
||||
// child: returnIconButtom,
|
||||
// ),
|
||||
Positioned(
|
||||
left: 0,
|
||||
child: returnIconButtom,
|
||||
left: 40.rpx,
|
||||
child: ClickableContainer(
|
||||
onTap: () {
|
||||
Get.offAllNamed("/mianPageBottomChange");
|
||||
},
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor: Colors
|
||||
.grey, // 可以设置为 themeController.currentColor.sc3 之类
|
||||
borderRadius: 8.rpx,
|
||||
padding: EdgeInsets.all(0.rpx), // 增加可点击区域
|
||||
child: SvgPicture.asset(
|
||||
'assets/img/icon/close.svg',
|
||||
width: 25.rpx,
|
||||
height: 25.rpx,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||||
import 'package:permission_handler/permission_handler.dart'; // 引入permission_handler
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
|
||||
import 'package:vbvs_app/controller/device/blueteeth_bind_controller.dart';
|
||||
import 'package:vbvs_app/controller/main_bottom/global_controller.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
@@ -51,6 +52,8 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
|
||||
flutterBlue = FlutterBluePlus(); // 初始化flutterBlue实例
|
||||
_checkBluetoothPermission(); // 检查蓝牙权限
|
||||
Get.find<BlueteethBindController>().startStatusPolling();
|
||||
blueteethBindController.search.value = "";
|
||||
blueteethBindController.currentDeviceMac?.value = "";
|
||||
}
|
||||
|
||||
// 检查蓝牙权限
|
||||
@@ -131,15 +134,94 @@ 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; // 确保页面未销毁
|
||||
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 searchKey =
|
||||
blueteethBindController.search.value.trim().toLowerCase();
|
||||
|
||||
final filteredResults = results.where((r) {
|
||||
final isTarget = r.rssi > signalThreshold &&
|
||||
r.advertisementData.localName == "AITH-V2" &&
|
||||
r.advertisementData.manufacturerData.containsKey(0xFFED);
|
||||
|
||||
if (!isTarget) return false;
|
||||
|
||||
// 搜索关键字过滤(根据名称和 MAC 地址模糊匹配)
|
||||
final name = r.advertisementData.advName.toLowerCase();
|
||||
final mac = r.device.remoteId.str.replaceAll(':', '').toLowerCase();
|
||||
final search = searchKey.trim().replaceAll(':', '').toLowerCase();
|
||||
|
||||
if (search.isNotEmpty &&
|
||||
!name.contains(search) &&
|
||||
!mac.contains(search)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}).toList();
|
||||
|
||||
// 解析数据
|
||||
final parsedDeviceList = <BleDeviceData>[];
|
||||
@@ -152,24 +234,23 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
|
||||
deviceData.rssi = r.rssi;
|
||||
deviceData.mac = deviceData.deviceId.replaceAll(':', '');
|
||||
parsedDeviceList.add(deviceData);
|
||||
if (deviceData.mac!.toLowerCase() == 'b43a45c3dfa0') {
|
||||
print('匹配设备数据: ${deviceData.mac}-->sn:${deviceData.sn}');
|
||||
}
|
||||
|
||||
// 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++) {
|
||||
@@ -183,11 +264,9 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
|
||||
}
|
||||
}
|
||||
|
||||
// 如果有变化,更新 devicelist 和 blelist
|
||||
if (hasChanges) {
|
||||
blueteethBindController.model.devicelist = parsedDeviceList;
|
||||
blueteethBindController.model.blelist = filteredResults;
|
||||
// blueteethBindController.updateDeviceStatus();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -360,6 +439,7 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
|
||||
newValue.toStringAsFixed(0));
|
||||
blueteethBindController.model.singal =
|
||||
newValue;
|
||||
_startScanning();
|
||||
blueteethBindController.updateAll();
|
||||
},
|
||||
);
|
||||
@@ -425,6 +505,12 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional(-1, 0),
|
||||
child: TextFormField(
|
||||
initialValue: blueteethBindController
|
||||
.search.value,
|
||||
onChanged: (Value) {
|
||||
blueteethBindController
|
||||
.search.value = Value;
|
||||
},
|
||||
autofocus: false,
|
||||
obscureText: false,
|
||||
decoration: InputDecoration(
|
||||
@@ -494,11 +580,8 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
|
||||
fontSize: 26.rpx,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
cursorColor: themeController
|
||||
.currentColor.sc3,
|
||||
// validator: _model
|
||||
// .textControllerValidator
|
||||
// .asValidator(context),
|
||||
cursorColor:
|
||||
themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -519,16 +602,60 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
|
||||
color: stringToColor("#333333"), //固定
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'搜索'.tr,
|
||||
style: FlutterFlowTheme.of(context)
|
||||
.bodyMedium
|
||||
.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 30.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: stringToColor("#333333"), //固定
|
||||
),
|
||||
ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor:
|
||||
themeController.currentColor.sc4,
|
||||
borderRadius: 6.rpx,
|
||||
padding: EdgeInsets.zero,
|
||||
// onTap: () async {
|
||||
|
||||
// blueteethBindController
|
||||
// .model.betDevicelist;
|
||||
// blueteethBindController.search.value;
|
||||
// blueteethBindController.updateAll();
|
||||
// },
|
||||
onTap: () async {
|
||||
// final searchKey = blueteethBindController
|
||||
// .search.value
|
||||
// .trim();
|
||||
// if (searchKey.isNotEmpty) {
|
||||
// final filtered = blueteethBindController
|
||||
// .model.betDevicelist!
|
||||
// .where((device) {
|
||||
// final name =
|
||||
// device.name?.toLowerCase() ?? '';
|
||||
// final mac =
|
||||
// device.mac?.toLowerCase() ?? '';
|
||||
// return name.contains(
|
||||
// searchKey.toLowerCase()) ||
|
||||
// mac.contains(
|
||||
// searchKey.toLowerCase());
|
||||
// }).toList();
|
||||
|
||||
// // 替换原始列表
|
||||
// blueteethBindController
|
||||
// .model.betDevicelist!
|
||||
// ..clear()
|
||||
// ..addAll(filtered);
|
||||
// }
|
||||
|
||||
// blueteethBindController.updateAll();
|
||||
_startScanning();
|
||||
},
|
||||
|
||||
child: Text(
|
||||
'搜索'.tr,
|
||||
style: FlutterFlowTheme.of(context)
|
||||
.bodyMedium
|
||||
.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 30.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color:
|
||||
stringToColor("#333333"), //固定
|
||||
),
|
||||
),
|
||||
),
|
||||
].divide(SizedBox(width: 26.rpx)),
|
||||
),
|
||||
@@ -548,8 +675,10 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
|
||||
EdgeInsetsDirectional.fromSTEB(19.rpx, 0, 0, 0),
|
||||
child: Obx(() {
|
||||
return Text(
|
||||
// '匹配出的外围设备'.tr +
|
||||
// "(${blueteethBindController.model.betDevicelist!.length})",
|
||||
'匹配出的外围设备'.tr +
|
||||
"(${blueteethBindController.model.betDevicelist!.length})",
|
||||
"(${blueteethBindController.model.blelist!.length})",
|
||||
style: FlutterFlowTheme.of(context)
|
||||
.bodyMedium
|
||||
.override(
|
||||
|
||||
@@ -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: [
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -89,7 +89,8 @@ class _CalibrationPageState extends State<CalibrationPage> {
|
||||
child: CustomCard(
|
||||
borderRadius: 20.rpx,
|
||||
onTap: () async {
|
||||
Get.toNamed("/personPage");
|
||||
// Get.toNamed("/personPage");
|
||||
Get.toNamed("/bindDeviceSuccess");
|
||||
},
|
||||
colors: [
|
||||
themeController.currentColor.sc1,
|
||||
|
||||
@@ -383,7 +383,7 @@ class _DeviceSharePageState extends State<DeviceSharePage> {
|
||||
// "太和e护分享链接",
|
||||
// scene: WeChatScene.session));
|
||||
final Uint8List data = await rootBundle.load('assets/img/camera.png').then((bd) => bd.buffer.asUint8List());
|
||||
loginController.fluwx.share(WeChatShareWebPageModel("https://www.baidu.com",title: "标题",description: "描述",thumbData: data));
|
||||
loginController.fluwx.share(WeChatShareWebPageModel("taihecare://goods?id=123",title: "标题",description: "描述",thumbData: data));
|
||||
},
|
||||
colors: [
|
||||
// 渐变色
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:easydevice/easydevice.dart';
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||||
@@ -15,6 +18,8 @@ import 'package:vbvs_app/controller/main_bottom/global_controller.dart';
|
||||
import 'package:vbvs_app/controller/person/person_controller.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
import 'package:vbvs_app/controller/user_info_controller.dart';
|
||||
import 'package:vbvs_app/model/BleDeviceData.dart';
|
||||
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 {
|
||||
@@ -36,10 +41,69 @@ class _WifiPageState extends State<WifiPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
blueteethBindController.connectStatus.value = 0;
|
||||
blueteethBindController.wifiList = [].obs;
|
||||
blueteethBindController.wifiStatus = 0.obs;
|
||||
blueteethBindController.connect_wifi.value = {};
|
||||
initWifiStatusAndWifiList();
|
||||
blueteethBindController.selectWifi.value = {};
|
||||
|
||||
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.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") {
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "4g设备配置wifi提示".tr,
|
||||
textColor: themeController.currentColor.sc2,
|
||||
);
|
||||
blueteethBindController.connectStatus.value = 1;
|
||||
blueteethBindController.updateAll();
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
Get.toNamed("/calibrationPage", arguments: 1);
|
||||
});
|
||||
} else {
|
||||
await initWifiStatusAndWifiList();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "连接失败".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
dealWifi(widget.type).then((aa) {
|
||||
print("object");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -79,14 +143,38 @@ class _WifiPageState extends State<WifiPage> {
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
/// 居中标题
|
||||
Text(
|
||||
'wifi页.标题'.tr,
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Readex Pro',
|
||||
color: themeController.currentColor.sc3,
|
||||
letterSpacing: 0,
|
||||
fontSize: 30.rpx,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'wifi页.标题'.tr,
|
||||
style:
|
||||
FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Readex Pro',
|
||||
color: themeController.currentColor.sc3,
|
||||
letterSpacing: 0,
|
||||
fontSize: 30.rpx,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 14.rpx,
|
||||
),
|
||||
Obx(() {
|
||||
if (blueteethBindController.connectStatus.value ==
|
||||
0) {
|
||||
return SizedBox(
|
||||
width: 24.rpx,
|
||||
height: 24.rpx,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 1,
|
||||
valueColor:
|
||||
AlwaysStoppedAnimation<Color>(Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Container();
|
||||
}),
|
||||
],
|
||||
),
|
||||
|
||||
/// 左边返回按钮
|
||||
@@ -100,15 +188,16 @@ class _WifiPageState extends State<WifiPage> {
|
||||
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);
|
||||
}
|
||||
// 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);
|
||||
},
|
||||
colors: [
|
||||
themeController.currentColor.sc1,
|
||||
@@ -460,8 +549,11 @@ class _WifiPageState extends State<WifiPage> {
|
||||
wifiItem['ssid'] ??
|
||||
'未命名'.tr,
|
||||
onConfirm: () async {
|
||||
showLoadingDialog(
|
||||
context); // 显示 loading
|
||||
// showLoadingDialog(
|
||||
// context); // 显示 loading
|
||||
blueteethBindController
|
||||
.selectWifi
|
||||
.value = wifiItem;
|
||||
bool flag = await sendWifiSetting(
|
||||
wifiItem,
|
||||
blueteethBindController
|
||||
@@ -478,7 +570,10 @@ class _WifiPageState extends State<WifiPage> {
|
||||
var aa = await getDeviceWifiStatus(
|
||||
blueteethBindController
|
||||
.currentDevice!,
|
||||
20);
|
||||
1);
|
||||
blueteethBindController
|
||||
.selectWifi
|
||||
.value = {};
|
||||
if (aa != null &&
|
||||
aa is Map) {
|
||||
wifiStatus = true;
|
||||
@@ -503,7 +598,7 @@ class _WifiPageState extends State<WifiPage> {
|
||||
? 1
|
||||
: 0;
|
||||
if (wifiStatus) {
|
||||
Navigator.pop(context);
|
||||
// Navigator.pop(context);
|
||||
TopSlideNotification
|
||||
.show(
|
||||
context,
|
||||
@@ -519,7 +614,7 @@ class _WifiPageState extends State<WifiPage> {
|
||||
blueteethBindController
|
||||
.updateAll();
|
||||
} else {
|
||||
Navigator.pop(context);
|
||||
// Navigator.pop(context);
|
||||
TopSlideNotification
|
||||
.show(
|
||||
context,
|
||||
@@ -536,7 +631,7 @@ class _WifiPageState extends State<WifiPage> {
|
||||
.updateAll();
|
||||
}
|
||||
} else {
|
||||
Navigator.pop(context);
|
||||
// Navigator.pop(context);
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "wifi页.配网失败".tr,
|
||||
@@ -574,7 +669,24 @@ class _WifiPageState extends State<WifiPage> {
|
||||
.sc3,
|
||||
),
|
||||
),
|
||||
getWifiIconByRsso(wifiItem),
|
||||
if (blueteethBindController
|
||||
.selectWifi.value ==
|
||||
wifiItem)
|
||||
SizedBox(
|
||||
width: 32.rpx,
|
||||
height: 32.rpx,
|
||||
child:
|
||||
CircularProgressIndicator(
|
||||
strokeWidth: 1,
|
||||
valueColor:
|
||||
AlwaysStoppedAnimation<
|
||||
Color>(
|
||||
Colors.white),
|
||||
),
|
||||
)
|
||||
else
|
||||
getWifiIconByRsso(
|
||||
wifiItem),
|
||||
],
|
||||
),
|
||||
))
|
||||
@@ -589,6 +701,9 @@ class _WifiPageState extends State<WifiPage> {
|
||||
horizontal: 20.rpx, vertical: 10.rpx),
|
||||
borderRadius: 20.rpx,
|
||||
onTap: () async {
|
||||
blueteethBindController
|
||||
.connectStatus.value = 0;
|
||||
blueteethBindController.updateAll();
|
||||
print("点击刷新");
|
||||
await initWifiList();
|
||||
TopSlideNotification.show(
|
||||
@@ -645,93 +760,92 @@ class _WifiPageState extends State<WifiPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDeviceCard(BuildContext context,
|
||||
{required String title, required String imageUrl, required String type}) {
|
||||
return CustomCard(
|
||||
borderRadius: 20.rpx, // 圆角大小
|
||||
onTap: () {
|
||||
if (type != null) {
|
||||
if (type == '1') {
|
||||
Get.toNamed("/blueteethDevice");
|
||||
}
|
||||
}
|
||||
},
|
||||
colors: [themeController.currentColor.sc17], // 背景色
|
||||
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
height: MediaQuery.sizeOf(context).height * 0.135,
|
||||
constraints: BoxConstraints(
|
||||
minHeight: 220.rpx,
|
||||
),
|
||||
padding: EdgeInsetsDirectional.fromSTEB(77.rpx, 0, 21.rpx, 0),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
color: const Color(0xFFC2CED7),
|
||||
fontSize: 30.rpx,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8.rpx),
|
||||
child: Image.asset(
|
||||
imageUrl,
|
||||
width: 212.rpx,
|
||||
height: 168.rpx,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void initWifiStatusAndWifiList() {
|
||||
Future<void> initWifiStatusAndWifiList() async {
|
||||
if (lisObj != null) {
|
||||
lisObj!.cancel();
|
||||
}
|
||||
bool wifiStatus = false;
|
||||
var aa =
|
||||
await getDeviceWifiStatus(blueteethBindController.currentDevice!, 1);
|
||||
if (aa != null && aa is Map) {
|
||||
wifiStatus = true;
|
||||
blueteethBindController.connect_wifi.value = aa;
|
||||
}
|
||||
blueteethBindController.wifiStatus.value = wifiStatus == true ? 1 : 0;
|
||||
List wifiList = [];
|
||||
try {
|
||||
final result = await getWifiList(blueteethBindController.currentDevice!);
|
||||
if (result is List) {
|
||||
wifiList = result;
|
||||
}
|
||||
} catch (e) {
|
||||
print("异常: $e");
|
||||
}
|
||||
if (wifiList.length > 0) {
|
||||
blueteethBindController.connectStatus.value = 1;
|
||||
blueteethBindController.updateAll();
|
||||
// Navigator.pop(context);
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "获取wifi列表成功".tr,
|
||||
textColor: themeController.currentColor.sc2,
|
||||
);
|
||||
blueteethBindController.wifiList.value = wifiList;
|
||||
blueteethBindController.updateAll();
|
||||
} else {
|
||||
// Navigator.pop(context);
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "获取wifi列表失败".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
}
|
||||
lisObj = blueteethBindController.currentDevice!.statusStream
|
||||
.listen((onData) async {
|
||||
if (onData.status == BleEventType.recvLineLog) {
|
||||
final line = onData.val;
|
||||
print("[bleee]:" + line);
|
||||
}
|
||||
if (onData.status == BleEventType.ready) {
|
||||
showLoadingDialog(context, title: "获取wifi列表中...".tr);
|
||||
bool wifiStatus = false;
|
||||
var aa = await getDeviceWifiStatus(
|
||||
blueteethBindController.currentDevice!, 10);
|
||||
if (aa != null && aa is Map) {
|
||||
wifiStatus = true;
|
||||
blueteethBindController.connect_wifi.value = aa;
|
||||
}
|
||||
blueteethBindController.wifiStatus.value = wifiStatus == true ? 1 : 0;
|
||||
List wifiList =
|
||||
await getWifiList(blueteethBindController.currentDevice!);
|
||||
if (wifiList.length > 0) {
|
||||
Navigator.pop(context);
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "获取wifi列表成功".tr,
|
||||
textColor: themeController.currentColor.sc2,
|
||||
);
|
||||
blueteethBindController.wifiList.value = wifiList;
|
||||
blueteethBindController.updateAll();
|
||||
} else {
|
||||
Navigator.pop(context);
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "获取wifi列表失败".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
}
|
||||
}
|
||||
// if (onData.status == BleEventType.ready) {
|
||||
// // showLoadingDialog(context, title: "获取wifi列表中...".tr);
|
||||
// bool wifiStatus = false;
|
||||
// var aa = await getDeviceWifiStatus(
|
||||
// blueteethBindController.currentDevice!, 1);
|
||||
// if (aa != null && aa is Map) {
|
||||
// wifiStatus = true;
|
||||
// blueteethBindController.connect_wifi.value = aa;
|
||||
// }
|
||||
// blueteethBindController.wifiStatus.value = wifiStatus == true ? 1 : 0;
|
||||
// List wifiList = [];
|
||||
// try {
|
||||
// final result =
|
||||
// await getWifiList(blueteethBindController.currentDevice!);
|
||||
// if (result is List) {
|
||||
// wifiList = result;
|
||||
// }
|
||||
// } catch (e) {
|
||||
// print("异常: $e");
|
||||
// }
|
||||
// if (wifiList.length > 0) {
|
||||
// blueteethBindController.connectStatus.value = 1;
|
||||
// blueteethBindController.updateAll();
|
||||
// // Navigator.pop(context);
|
||||
// TopSlideNotification.show(
|
||||
// context,
|
||||
// text: "获取wifi列表成功".tr,
|
||||
// textColor: themeController.currentColor.sc2,
|
||||
// );
|
||||
// blueteethBindController.wifiList.value = wifiList;
|
||||
// blueteethBindController.updateAll();
|
||||
// } else {
|
||||
// Navigator.pop(context);
|
||||
// TopSlideNotification.show(
|
||||
// context,
|
||||
// text: "获取wifi列表失败".tr,
|
||||
// textColor: themeController.currentColor.sc9,
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -740,6 +854,8 @@ class _WifiPageState extends State<WifiPage> {
|
||||
var wifiList = await getWifiList(blueteethBindController.currentDevice!);
|
||||
print(wifiList);
|
||||
if (wifiList.length > 0) {
|
||||
blueteethBindController.connectStatus.value = 1;
|
||||
|
||||
blueteethBindController.wifiList.value = wifiList;
|
||||
blueteethBindController.updateAll();
|
||||
}
|
||||
@@ -802,4 +918,150 @@ 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>();
|
||||
|
||||
// 显示加载对话框
|
||||
// showLoadingDialog(Get.context!, title: "连接中...".tr);
|
||||
|
||||
// 设置超时定时器
|
||||
Timer? timeoutTimer;
|
||||
bool isConnected = false;
|
||||
|
||||
try {
|
||||
// 开始扫描蓝牙设备
|
||||
await FlutterBluePlus.startScan(timeout: Duration(seconds: 10));
|
||||
|
||||
// 设置超时(20秒)
|
||||
timeoutTimer = Timer(Duration(seconds: 20), () {
|
||||
try {
|
||||
if (!isConnected) {
|
||||
// Navigator.of(context).pop(); // 先关闭 dialog
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "设备连接超时,请重试".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
});
|
||||
FlutterBluePlus.stopScan();
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
});
|
||||
|
||||
// 监听扫描结果
|
||||
StreamSubscription<List<ScanResult>>? scanSubscription;
|
||||
scanSubscription = FlutterBluePlus.scanResults.listen((results) async {
|
||||
// 过滤出符合条件的设备
|
||||
ScanResult? targetDevice;
|
||||
|
||||
for (var r in results) {
|
||||
if (r.advertisementData.manufacturerData.containsKey(0xFFED)) {
|
||||
List<int> rawData = r.advertisementData.manufacturerData[0xFFED]!;
|
||||
BleDeviceData deviceData = parseBleData(rawData);
|
||||
String deviceMac =
|
||||
deviceData.deviceId.replaceAll(':', '').toLowerCase();
|
||||
if (deviceMac == mac.toLowerCase()) {
|
||||
targetDevice = r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (targetDevice != null && !isConnected) {
|
||||
isConnected = true;
|
||||
FlutterBluePlus.stopScan();
|
||||
scanSubscription?.cancel();
|
||||
timeoutTimer?.cancel();
|
||||
|
||||
try {
|
||||
// 连接设备
|
||||
// await targetDevice.device.connect();
|
||||
THapp bledevice = THapp(device: targetDevice.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;
|
||||
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") {
|
||||
// TopSlideNotification.show(
|
||||
// Get.context!,
|
||||
// text: "4g设备配置wifi提示".tr,
|
||||
// textColor: themeController.currentColor.sc9,
|
||||
// );
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "4g设备配置wifi提示".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
// Get.toNamed("/wifiPage", arguments: 2);
|
||||
await initWifiStatusAndWifiList();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Get.toNamed("/wifiPage", arguments: {bledevice});
|
||||
} else {
|
||||
// Navigator.pop(context);
|
||||
TopSlideNotification.show(
|
||||
context,
|
||||
text: "蓝牙绑定.连接失败".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
// Navigator.of(Get.context!).pop(); // 关闭加载对话框
|
||||
TopSlideNotification.show(
|
||||
Get.context!,
|
||||
text: "设备连接失败".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 等待扫描完成
|
||||
await Future.delayed(Duration(seconds: 20));
|
||||
} catch (e) {
|
||||
timeoutTimer?.cancel();
|
||||
Navigator.of(Get.context!).pop(); // 关闭加载对话框
|
||||
TopSlideNotification.show(
|
||||
Get.context!,
|
||||
text: "扫描过程中发生错误".tr,
|
||||
textColor: themeController.currentColor.sc9,
|
||||
);
|
||||
} finally {
|
||||
timeoutTimer?.cancel();
|
||||
await FlutterBluePlus.stopScan();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user