更新
This commit is contained in:
@@ -7,12 +7,14 @@ import 'package:flutter_svg/svg.dart';
|
||||
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:vbvs_app/common/color/appConstants.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';
|
||||
import 'package:vbvs_app/component/tool/ClickableContainer.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/pages/common/selectDialog.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/component/mht_bind_dialog.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/device/component/DeviceComponentWidget.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/device/controller/mht_bluetooth_controller.dart';
|
||||
@@ -72,12 +74,92 @@ class _MHTBlueteethDevicePageState extends State<MHTBlueteethDevicePage> {
|
||||
}
|
||||
}
|
||||
|
||||
// Future<void> _requestBluetoothPermission() async {
|
||||
// // showPermissionInfoDialog(Get.context!, CommonVariables().permissionInfo);
|
||||
// // Map<Permission, PermissionStatus> statuses = await [
|
||||
// // Permission.bluetoothScan,
|
||||
// // Permission.bluetoothConnect,
|
||||
// // Permission.location,
|
||||
// // ].request();
|
||||
// Map<Permission, PermissionStatus> statuses = {};
|
||||
// try {
|
||||
// // 1️⃣ 先显示自定义提示弹窗
|
||||
// showPermissionInfoDialog(Get.context!, CommonVariables().permissionInfo);
|
||||
|
||||
// // 2️⃣ 等待一小会,让 UI 有时间渲染提示弹窗
|
||||
// await Future.delayed(const Duration(milliseconds: 300));
|
||||
|
||||
// // 3️⃣ 再去申请权限(系统权限弹窗可能会弹出)
|
||||
// statuses = await [
|
||||
// Permission.bluetoothScan,
|
||||
// Permission.bluetoothConnect,
|
||||
// Permission.location,
|
||||
// ].request();
|
||||
|
||||
// // 这里你可以检查每个权限的状态
|
||||
// ef.log("权限状态: $statuses");
|
||||
// } catch (e) {
|
||||
// ef.log("申请权限出错: $e");
|
||||
// } finally {
|
||||
// // 4️⃣ 无论成功失败,最后关闭提示弹窗
|
||||
// if (Get.context != null) {
|
||||
// Navigator.of(Get.context!, rootNavigator: true).pop();
|
||||
// }
|
||||
// }
|
||||
|
||||
// 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() async {
|
||||
Map<Permission, PermissionStatus> statuses = await [
|
||||
Permission.bluetoothScan,
|
||||
Permission.bluetoothConnect,
|
||||
Permission.location,
|
||||
].request();
|
||||
Map<Permission, PermissionStatus> statuses = {};
|
||||
bool dialogShown = false; // 标记是否弹过权限提示弹窗
|
||||
|
||||
try {
|
||||
// 检查是否已授权
|
||||
bool alreadyGranted = await Permission.bluetoothScan.isGranted &&
|
||||
await Permission.bluetoothConnect.isGranted &&
|
||||
await Permission.location.isGranted;
|
||||
|
||||
if (!alreadyGranted) {
|
||||
// 弹出自定义提示
|
||||
showPermissionInfoDialog(
|
||||
Get.context!, CommonVariables().permissionInfo);
|
||||
dialogShown = true;
|
||||
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
|
||||
// 请求权限
|
||||
statuses = await [
|
||||
Permission.bluetoothScan,
|
||||
Permission.bluetoothConnect,
|
||||
Permission.location,
|
||||
].request();
|
||||
|
||||
ef.log("权限状态: $statuses");
|
||||
} else {
|
||||
statuses = {
|
||||
Permission.bluetoothScan: PermissionStatus.granted,
|
||||
Permission.bluetoothConnect: PermissionStatus.granted,
|
||||
Permission.location: PermissionStatus.granted,
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
ef.log("申请权限出错: $e");
|
||||
} finally {
|
||||
// 只有真的弹过提示才关闭
|
||||
if (dialogShown && Get.context != null) {
|
||||
Navigator.of(Get.context!, rootNavigator: true).pop();
|
||||
}
|
||||
}
|
||||
|
||||
bool allGranted = statuses[Permission.bluetoothScan]?.isGranted == true &&
|
||||
statuses[Permission.bluetoothConnect]?.isGranted == true &&
|
||||
|
||||
Reference in New Issue
Block a user