更新睡眠报告提示样式,更新ios蓝牙开关判定

This commit is contained in:
wyf
2025-09-04 11:20:44 +08:00
parent aad3a00ac3
commit 9f73a8111a
12 changed files with 1845 additions and 277 deletions

View File

@@ -8,6 +8,7 @@ import 'package:flutter_svg/svg.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:permission_handler/permission_handler.dart'; // 引入permission_handler
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/BluetoothHelper.dart';
import 'package:vbvs_app/common/util/CommonVariables.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
@@ -60,6 +61,23 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
Get.find<BlueteethBindController>().startStatusPolling();
blueteethBindController.search.value = "";
blueteethBindController.currentDeviceMac?.value = "";
BluetoothHelper.listenBluetoothState((isOn) {
blueteethBindController.model.bluetooth = isOn;
if (isOn) {
isScanning = false;
_startScanning();
}
blueteethBindController.updateAll();
if (!isOn && !_isDialogShowing) {
_isDialogShowing = true;
blueteethBindController.model.devicelist = [];
blueteethBindController.model.betDevicelist = [];
blueteethBindController.updateAll();
_showBluetoothNotEnabledDialog().then((_) {
_isDialogShowing = false;
});
}
});
}
// 检查蓝牙权限
@@ -77,27 +95,6 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
}
}
// Future<void> _requestBluetoothPermission() async {
// Map<Permission, PermissionStatus> statuses = await [
// Permission.bluetoothScan,
// Permission.bluetoothConnect,
// Permission.location, // Android 12 及以下仍需要位置权限来进行扫描
// ].request();
// bool allGranted = statuses[Permission.bluetoothScan]?.isGranted == true &&
// statuses[Permission.bluetoothConnect]?.isGranted == true &&
// statuses[Permission.location]?.isGranted == true;
// if (allGranted) {
// // 用户授予了权限,开始扫描
// _startScanning();
// _startPeriodicScan();
// } else {
// // 权限被拒绝,提示用户
// _showPermissionDeniedDialog();
// }
// }
Future<void> _requestBluetoothPermission(BuildContext context) async {
Map<Permission, PermissionStatus> statuses = {};
bool dialogShown = false; // 标记是否弹过权限提示弹窗
@@ -200,15 +197,15 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
if (!mounted || isScanning) return;
_scanSubscription?.cancel();
var bluetoothState = await FlutterBluePlus.isOn;
if (!bluetoothState && !_isDialogShowing) {
_isDialogShowing = true;
blueteethBindController.model.blelist = [];
blueteethBindController.updateAll();
await _showBluetoothNotEnabledDialog();
_isDialogShowing = false;
return;
}
// var bluetoothState = await FlutterBluePlus.isOn;
// if (!bluetoothState && !_isDialogShowing) {
// _isDialogShowing = true;
// blueteethBindController.model.blelist = [];
// blueteethBindController.updateAll();
// await _showBluetoothNotEnabledDialog();
// _isDialogShowing = false;
// return;
// }
if (!isScanning) {
setState(() {