更新设备校准

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

@@ -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(