更新登录对接

This commit is contained in:
wyf
2025-04-18 18:13:21 +08:00
parent 1765403f21
commit 850c34b408
40 changed files with 2101 additions and 1745 deletions

View File

@@ -1,22 +1,25 @@
import 'package:ef/base/widget/flutterflow/FlutterFlowTheme.dart';
import 'package:EasyDartModule/EasyDartModule.dart' as edm;
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:flutterflow_ui/flutterflow_ui.dart';
import 'package:vbvs_app/common/color/app_uri_status.dart';
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/controller/device/blueteeth_bind_controller.dart';
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
import 'package:vbvs_app/model/BleDeviceData.dart';
import 'package:vbvs_app/model/api_response.dart';
import 'package:vbvs_app/pages/device_bind/blueteeth_device_page.dart';
import 'package:vbvs_app/pages/device_bind/componnet/bind_dialog.dart';
class SingleBlueteethDeviceCompoentWidget extends StatefulWidget {
// final BleDeviceData device;
final bleDevice;
const SingleBlueteethDeviceCompoentWidget({
super.key,
// required this.device,
required this.bleDevice,
});
@@ -27,9 +30,10 @@ class SingleBlueteethDeviceCompoentWidget extends StatefulWidget {
class _SingleBlueteethDeviceCompoentWidgetState
extends State<SingleBlueteethDeviceCompoentWidget> {
ThemeController themeController = Get.find();
BlueteethBindController blueteethBindController = Get.find();
@override
Widget build(BuildContext context) {
var bleDevice = widget.bleDevice;
List<int> rawData =
widget.bleDevice.advertisementData.manufacturerData[0xFFED]!;
BleDeviceData deviceData = parseBleData(rawData);
@@ -37,45 +41,80 @@ class _SingleBlueteethDeviceCompoentWidgetState
deviceData.rssi = widget.bleDevice.rssi;
deviceData.mac = deviceData.deviceId.replaceAll(':', '');
BleDeviceData device = deviceData;
device = blueteethBindController.model.devicelist!.firstWhere(
(d) => d.mac == device.mac,
orElse: () => device,
);
ThemeController themeController = Get.find();
return ClickableContainer(
backgroundColor: themeController.currentColor.sc5,
highlightColor: Colors.white,
highlightColor: themeController.currentColor.sc21,
borderRadius: 20.rpx,
padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 36.rpx, 0, 52.rpx),
onTap: () async {
//todo 请求绑定
print(device.mac);
// try {
// await bleDevice.device.connect(autoConnect: false);
// List<BluetoothService> services =
// await bleDevice.device.discoverServices();
// BluetoothCharacteristic? wifiListChar;
// BluetoothCharacteristic? wifiSsidChar;
// BluetoothCharacteristic? wifiPasswordChar;
// BluetoothCharacteristic? startProvisionChar;
// for (BluetoothService service in services) {
// for (BluetoothCharacteristic c in service.characteristics) {
// if (c.uuid.toString() == 'YOUR_WIFI_LIST_UUID') {
// wifiListChar = c;
// } else if (c.uuid.toString() == 'YOUR_WIFI_SSID_UUID') {
// wifiSsidChar = c;
// } else if (c.uuid.toString() == 'YOUR_WIFI_PWD_UUID') {
// wifiPasswordChar = c;
// } else if (c.uuid.toString() == 'YOUR_WIFI_START_UUID') {
// startProvisionChar = c;
// }
// }
// }
// } catch (e) {
// print("蓝牙连接失败");
// }
//
// Get.toNamed('/wifiPage', arguments: bleDevice.device);
showBindDoubleDialog(context,[]);
// showHaveBindDialog(context);
try {
if (device.bind == true) {
showHaveBindDialog(context);
// showBindDoubleDialog(context, []);
} else {
showConfirmDialog(
context,
Container(),
'蓝牙绑定.确定绑定提示'.tr,
onConfirm: () async {
ApiResponse response =
await blueteethBindController.bindDeviceAndMAC(device);
if (response.code == HttpStatusCodes.ok) {
showLoadingDialog(context); // 显示 loading
BLEDevice bledevice =
BLEDevice(device: widget.bleDevice.device);
var res1 = bledevice.isConnected;
print("res1: $res1");
await bledevice.device.connect();
var res2 = bledevice.isConnected;
print("res2: $res2");
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,
);
}
} else {
TopSlideNotification.show(
context,
text: "蓝牙绑定.连接异常".tr,
textColor: themeController.currentColor.sc9,
);
}
},
onCancel: () {
print('用户点击了取消');
// 执行取消后的处理逻辑
},
);
}
} catch (e) {
Navigator.pop(context);
TopSlideNotification.show(
context,
text: "蓝牙绑定.连接异常".tr,
textColor: themeController.currentColor.sc9,
);
edm.EasyDartModule.logger.info("蓝牙绑定.连接异常: $e");
DailyLogUtils.writeLog("蓝牙绑定.连接异常: $e");
}
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -156,10 +195,12 @@ class _SingleBlueteethDeviceCompoentWidgetState
),
),
Text(
device.status == 1 ? '蓝牙绑定.可绑定'.tr : '蓝牙绑定.已被绑定'.tr,
device.bind == false ? '蓝牙绑定.可绑定'.tr : '蓝牙绑定.已被绑定'.tr,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Inter',
color: const Color(0xFF1AD2B5),
color: device.bind == false
? const Color(0xFF1AD2B5)
: themeController.currentColor.sc9,
fontSize: 26.rpx,
letterSpacing: 0.0,
),