权限,检出分支
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -27,7 +27,7 @@ class QrCodePage extends GetView<QrCodeController> {
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: controller.scanFromGallery,
|
||||
onPressed: controller.requestPhotoPermission,
|
||||
child: const Text(
|
||||
'相册',
|
||||
style: TextStyle(color: Colors.white, fontSize: 16),
|
||||
|
||||
Reference in New Issue
Block a user