|
|
@ -1,17 +1,18 @@ |
|
|
|
|
|
import 'dart:io'; |
|
|
|
|
|
import 'dart:async'; |
|
|
|
|
|
|
|
|
import 'package:app_settings/app_settings.dart'; |
|
|
import 'package:app_settings/app_settings.dart'; |
|
|
import 'package:voitrans/data/models/appconfig_model.dart'; |
|
|
|
|
|
import '/data/models/appconfig.dart'; |
|
|
|
|
|
import '/data/models/user_Info.dart'; |
|
|
|
|
|
import '/data/services/network/api.dart'; |
|
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
import 'dart:async'; |
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart'; |
|
|
import 'package:permission_handler/permission_handler.dart'; |
|
|
import 'package:url_launcher/url_launcher.dart'; |
|
|
import 'package:url_launcher/url_launcher.dart'; |
|
|
import '../../../routes/app_routes.dart'; |
|
|
import '../../../routes/app_routes.dart'; |
|
|
import '../../../core/utils/logger.dart'; |
|
|
import '../../../core/utils/logger.dart'; |
|
|
import 'dart:io'; |
|
|
import '/data/models/appconfig_model.dart'; |
|
|
|
|
|
import '/data/models/appconfig.dart'; |
|
|
|
|
|
import '/data/models/user_Info.dart'; |
|
|
|
|
|
import '/data/services/network/api.dart'; |
|
|
import '../../../data/services/bluetooth_manager.dart'; |
|
|
import '../../../data/services/bluetooth_manager.dart'; |
|
|
import '../../../data/services/ble_manager.dart'; |
|
|
import '../../../data/services/ble_manager.dart'; |
|
|
import '../../../core/utils/permission_util.dart'; |
|
|
import '../../../core/utils/permission_util.dart'; |
|
|
@ -347,7 +348,7 @@ class PairingController extends GetxController with WidgetsBindingObserver { |
|
|
void _handleBleStateChange(int state) { |
|
|
void _handleBleStateChange(int state) { |
|
|
if (_currentState.value == PairingState.waitingBle) { |
|
|
if (_currentState.value == PairingState.waitingBle) { |
|
|
if (state == 2) { |
|
|
if (state == 2) { |
|
|
// BLE已连接 |
|
|
// 2代表BLE已连接 |
|
|
_bleTimeoutTimer?.cancel(); |
|
|
_bleTimeoutTimer?.cancel(); |
|
|
_transition(PairingState.completed); |
|
|
_transition(PairingState.completed); |
|
|
} |
|
|
} |
|
|
@ -501,32 +502,33 @@ class PairingController extends GetxController with WidgetsBindingObserver { |
|
|
/// 检查当前状态并决定下一步 |
|
|
/// 检查当前状态并决定下一步 |
|
|
void _checkCurrentStatus() async { |
|
|
void _checkCurrentStatus() async { |
|
|
try { |
|
|
try { |
|
|
// 1. 检查蓝牙状态 |
|
|
// 1. 并行检查蓝牙状态、权限、设备连接 |
|
|
final results = await Future.wait([ |
|
|
final results = await Future.wait([ |
|
|
_checkBluetoothState(), // 检查蓝牙状态 |
|
|
_checkBluetoothState(), // 检查蓝牙是否开启 |
|
|
_checkPermissions(), // 检查权限 |
|
|
_checkPermissions(), // 检查蓝牙相关权限 |
|
|
_bluetoothManager.refreshDeviceConnection(), // 刷新设备连接 |
|
|
_bluetoothManager.refreshDeviceConnection(), // 刷新设备连接状态 |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
final isBluetoothOk = results[0] as bool; |
|
|
final isBluetoothOk = results[0] as bool; |
|
|
final arePermissionsOk = results[1] as bool; |
|
|
final arePermissionsOk = results[1] as bool; |
|
|
|
|
|
|
|
|
|
|
|
//蓝牙没开 |
|
|
if (!isBluetoothOk) { |
|
|
if (!isBluetoothOk) { |
|
|
_setError( |
|
|
_setError( |
|
|
ErrorType.bluetoothOff, 'connectDeepSoundViaSystemBluetooth'.tr); |
|
|
ErrorType.bluetoothOff, 'connectDeepSoundViaSystemBluetooth'.tr); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 2. 检查权限 |
|
|
//权限不够 |
|
|
if (!arePermissionsOk) { |
|
|
if (!arePermissionsOk) { |
|
|
_setError(ErrorType.noPermission, 'pleaseGrantNecessaryPermissions'.tr); |
|
|
_setError(ErrorType.noPermission, 'pleaseGrantNecessaryPermissions'.tr); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 3. 先刷新设备连接状态,确保获取最新的连接信息 |
|
|
// 2. 先刷新设备连接状态,确保获取最新的连接信息 |
|
|
await _bluetoothManager.refreshDeviceConnection(); |
|
|
//await _bluetoothManager.refreshDeviceConnection(); |
|
|
|
|
|
|
|
|
// 4. 检查经典蓝牙连接 |
|
|
// 3. 检查经典蓝牙连接 |
|
|
final classicDevice = _bluetoothManager.currentDevice; |
|
|
final classicDevice = _bluetoothManager.currentDevice; |
|
|
if (classicDevice == null) { |
|
|
if (classicDevice == null) { |
|
|
_transition(PairingState.waitingClassic); |
|
|
_transition(PairingState.waitingClassic); |
|
|
@ -543,7 +545,7 @@ class PairingController extends GetxController with WidgetsBindingObserver { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// 新增一个辅助方法来检查蓝牙状态 |
|
|
/// 检查蓝牙状态是否开启 |
|
|
Future<bool> _checkBluetoothState() async { |
|
|
Future<bool> _checkBluetoothState() async { |
|
|
return _bluetoothManager.bluetoothState != 'off'; |
|
|
return _bluetoothManager.bluetoothState != 'off'; |
|
|
} |
|
|
} |
|
|
@ -727,7 +729,7 @@ class PairingController extends GetxController with WidgetsBindingObserver { |
|
|
// 检查设备名称是否包含 DeepSound 或 DeapSound |
|
|
// 检查设备名称是否包含 DeepSound 或 DeapSound |
|
|
final deviceName = device.name; |
|
|
final deviceName = device.name; |
|
|
DBProduct? product; |
|
|
DBProduct? product; |
|
|
// 检查是否已有BLE绑定的设备 |
|
|
|
|
|
/// 检查是否已有BLE绑定的设备 |
|
|
/// 检查是否已有BLE绑定的设备 |
|
|
if (AppConfig.config.products.isNotEmpty) { |
|
|
if (AppConfig.config.products.isNotEmpty) { |
|
|
final match = AppConfig.config.products.where( |
|
|
final match = AppConfig.config.products.where( |
|
|
|