扫码无权限优化,司机预约多弹窗
This commit is contained in:
@@ -24,6 +24,8 @@ class QrCodeController extends GetxController
|
||||
final RxBool isFlashOn = false.obs;
|
||||
final RxBool isProcessingResult = false.obs;
|
||||
|
||||
final RxBool hasPermission = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -47,7 +49,6 @@ class QrCodeController extends GetxController
|
||||
isProcessingResult.value = true;
|
||||
scannerController.stop();
|
||||
animationController.stop();
|
||||
print("相机识别到的内容: ${barcode.rawValue!}");
|
||||
renderResult(barcode.rawValue!);
|
||||
}
|
||||
}
|
||||
@@ -57,10 +58,10 @@ class QrCodeController extends GetxController
|
||||
isProcessingResult.value = false;
|
||||
try {
|
||||
scannerController.start();
|
||||
animationController.repeat(reverse: false);
|
||||
} catch (e) {
|
||||
print("无法重启相机: $e");
|
||||
}
|
||||
animationController.repeat(reverse: false);
|
||||
}
|
||||
|
||||
/// 从相册选择图片并扫描二维码
|
||||
@@ -120,10 +121,19 @@ class QrCodeController extends GetxController
|
||||
/// 请求相机权限
|
||||
void requestPermission() async {
|
||||
var status = await Permission.camera.request();
|
||||
|
||||
hasPermission.value = status.isGranted;
|
||||
|
||||
if (!status.isGranted) {
|
||||
showErrorToast('请授予相机权限以使用扫描功能');
|
||||
Get.back();
|
||||
if (status.isPermanentlyDenied) {
|
||||
showErrorToast('相机权限已被永久拒绝,请到系统设置中开启');
|
||||
// 延迟一会再引导用户去设置
|
||||
Future.delayed(const Duration(seconds: 2), () => openAppSettings());
|
||||
} else {
|
||||
showErrorToast('请授予相机权限以使用扫描功能');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void requestPhotoPermission() async {
|
||||
|
||||
Reference in New Issue
Block a user