更新登录对接

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,6 +1,7 @@
import 'dart:async';
import 'package:ef/ef.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:flutter_svg/svg.dart';
@@ -10,6 +11,7 @@ import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.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';
import 'package:vbvs_app/controller/user_info_controller.dart';
import 'package:vbvs_app/model/BleDeviceData.dart';
import 'package:vbvs_app/pages/common/selectDialog.dart';
@@ -28,6 +30,7 @@ class _EPageState extends State<BlueteethDevicePage> {
GlobalController globalController = Get.find();
UserInfoController userInfoController = Get.find();
BlueteethBindController blueteethBindController = Get.find();
ThemeController themeController = Get.find();
late FlutterBluePlus flutterBlue; // 声明 flutterBlue 实例
List<ScanResult> scanResults = []; // 存储扫描到的设备
bool isScanning = false; // 扫描状态控制
@@ -48,6 +51,7 @@ class _EPageState extends State<BlueteethDevicePage> {
super.initState();
flutterBlue = FlutterBluePlus(); // 初始化flutterBlue实例
_checkBluetoothPermission(); // 检查蓝牙权限
Get.find<BlueteethBindController>().startStatusPolling();
}
// 检查蓝牙权限
@@ -125,29 +129,6 @@ class _EPageState extends State<BlueteethDevicePage> {
await FlutterBluePlus.startScan(timeout: Duration(seconds: 10));
// FlutterBluePlus.scanResults.listen((results) {
// // 使用 controller 中设定的最小信号强度过滤
// final signalThreshold = blueteethBindController.model.singal!;
// final filteredResults = results
// .where((r) =>
// r.rssi > signalThreshold &&
// r.advertisementData.localName == "AITH-V2")
// .toList();
// setState(() {
// scanResults = filteredResults;
// print("过滤后设备数量:${filteredResults.length}");
// blueteethBindController.model.devicelist = filteredResults;
// blueteethBindController.updateAll();
// if (filteredResults.isNotEmpty) {
// for (var r in filteredResults) {
// print("设备名: ${r.device.name}, RSSI: ${r.rssi}");
// }
// } else {
// print("没有找到符合条件的设备");
// }
// });
// });
FlutterBluePlus.scanResults.listen((results) {
final signalThreshold = blueteethBindController.model.singal!;
final filteredResults = results
@@ -173,24 +154,35 @@ class _EPageState extends State<BlueteethDevicePage> {
}
}
// 使用一个临时变量 lastDeviceList 来比较是否有变化
setState(() {
scanResults = filteredResults;
bool hasChanges = false;
// 存入 controller 中
blueteethBindController.model.blelist = filteredResults;
blueteethBindController.model.devicelist = parsedDeviceList;
blueteethBindController.updateDeviceStatus();
blueteethBindController.updateAll();
// 如果 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;
}
}
}
// print("过滤并解析后设备数量:${parsedDeviceList.length}");
// for (var device in parsedDeviceList) {
// print(
// "设备: ${device.deviceId}, HR: ${device.ht}, BRE: ${device.bre}, Seq: ${device.fullSeq}");
// }
// if (parsedDeviceList.isEmpty) {
// print("没有符合条件的 BLE 广播数据");
// }
// 如果有变化,更新 devicelist 和 blelist
if (hasChanges) {
blueteethBindController.model.devicelist = parsedDeviceList;
blueteethBindController.model.blelist = filteredResults;
// blueteethBindController.updateDeviceStatus();
}
});
});
@@ -206,7 +198,7 @@ class _EPageState extends State<BlueteethDevicePage> {
}
}
// 定时每10秒进行一次扫描
// 定时每10秒进行一次扫描
void _startPeriodicScan() {
_timer = Timer.periodic(Duration(seconds: 10), (timer) {
if (!isScanning) {
@@ -637,8 +629,8 @@ class _EPageState extends State<BlueteethDevicePage> {
child: Scaffold(
backgroundColor: Colors.transparent, // 加上这一行
appBar: AppBar(
iconTheme: IconThemeData(color: Colors.white),
backgroundColor: stringToColor("#242835"),
iconTheme: IconThemeData(color: themeController.currentColor.sc3),
backgroundColor: themeController.currentColor.sc17,
automaticallyImplyLeading: false,
titleSpacing: 0,
title: Container(
@@ -651,7 +643,7 @@ class _EPageState extends State<BlueteethDevicePage> {
'蓝牙绑定.标题'.tr,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Readex Pro',
color: Colors.white,
color: themeController.currentColor.sc3,
letterSpacing: 0,
fontSize: 30.rpx,
),
@@ -763,7 +755,7 @@ class _EPageState extends State<BlueteethDevicePage> {
Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
color: themeController.currentColor.sc3,
borderRadius: BorderRadius.circular(20.rpx),
),
child: Padding(
@@ -776,7 +768,7 @@ class _EPageState extends State<BlueteethDevicePage> {
Expanded(
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
children: [
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
0, 0.rpx, 0, 0),
@@ -788,7 +780,7 @@ class _EPageState extends State<BlueteethDevicePage> {
child: SvgPicture.asset(
'assets/img/icon/query.svg',
fit: BoxFit.cover,
color: Colors.black,
color: stringToColor("#333333"), //固定
),
),
),
@@ -861,10 +853,9 @@ class _EPageState extends State<BlueteethDevicePage> {
borderRadius:
BorderRadius.circular(8.rpx),
),
filled: true,
fillColor:
FlutterFlowTheme.of(context)
.secondaryBackground,
filled: false,
fillColor: themeController
.currentColor.sc22,
),
style: FlutterFlowTheme.of(context)
.bodyMedium
@@ -896,8 +887,7 @@ class _EPageState extends State<BlueteethDevicePage> {
height: 50.rpx,
child: VerticalDivider(
thickness: 2.rpx,
color: FlutterFlowTheme.of(context)
.alternate,
color: stringToColor("#333333"), //固定
),
),
Text(
@@ -908,6 +898,7 @@ class _EPageState extends State<BlueteethDevicePage> {
fontFamily: 'Inter',
fontSize: 30.rpx,
letterSpacing: 0.0,
color: stringToColor("#333333"), //固定
),
),
].divide(SizedBox(width: 26.rpx)),
@@ -931,35 +922,38 @@ class _EPageState extends State<BlueteethDevicePage> {
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: 'Inter',
fontSize: 30.rpx,
letterSpacing: 0.0,
color: Colors.white),
fontFamily: 'Inter',
fontSize: 30.rpx,
letterSpacing: 0.0,
color: themeController.currentColor.sc3,
),
),
),
),
),
Expanded(
child: Container(
width: double.infinity,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
...blueteethBindController.model.blelist!
.map((device) =>
SingleBlueteethDeviceCompoentWidget(
// device: device,
bleDevice: device,
))
.toList()
.divide(SizedBox(height: 30.rpx))
.addToEnd(SizedBox(height: 30.rpx)),
],
Obx(() {
return Expanded(
child: Container(
width: double.infinity,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
...blueteethBindController.model.blelist!
.map((device) =>
SingleBlueteethDeviceCompoentWidget(
// device: device,
bleDevice: device,
))
.toList()
.divide(SizedBox(height: 30.rpx))
.addToEnd(SizedBox(height: 30.rpx)),
],
),
),
),
),
),
);
}),
].divide(SizedBox(height: 30.rpx)),
),
),