权限,检出分支

This commit is contained in:
2025-11-25 14:41:21 +08:00
parent 9e8df74622
commit 29fc16f2ff
5 changed files with 47 additions and 16 deletions

View File

@@ -125,19 +125,46 @@ class QrCodeController extends GetxController
}
void requestPermission() async {
final List<bool> results = await Future.wait([
requestCameraPermission(),
requestPhotosPermission(),
]);
if(Platform.isIOS){
var status = await Permission.camera.request();
if (status.isGranted) {
}
else if (status.isPermanentlyDenied) {
openAppSettings();
}
else {
showErrorToast('需要相机权限才能扫描二维码');
}
return;
}
final isCameraGranted = results[0];
final isPhotosGranted = results[1];
if (!isCameraGranted) {
final bool results = await requestCameraPermission();
if (!results) {
showErrorToast('相机权限未被授予,请到权限管理中打开');
}
if (!isPhotosGranted) {
showErrorToast('相册权限未被授予,请到权限管理中打开');
}
void requestPhotoPermission() async {
if (Platform.isAndroid) {
final bool results = await requestPhotosPermission();
if (!results) {
showErrorToast('相册权限未被授予,请到权限管理中打开');
} else {
scanFromGallery();
}
}
if(Platform.isIOS){
var status = await Permission.photos.request();
print("权限状态: $status"); // 在控制台看这个输出
if (status.isGranted) {
scanFromGallery();
}
else if (status.isPermanentlyDenied) {
openAppSettings();
}
else {
showErrorToast('需要相册权限才能从相册中选择图片');
}
}
}
@@ -161,7 +188,6 @@ class QrCodeController extends GetxController
await StorageService.to.saveVehicleInfo(vehicle);
Get.back(result: true);
} on DioException catch (e) {
showErrorToast("网络请求失败,请稍后重试");
resumeScanner();
@@ -173,7 +199,6 @@ class QrCodeController extends GetxController
}
}
@override
void onClose() {
qrViewController?.dispose();