From 5f5579dc5a879138341069191068e044a04921cd Mon Sep 17 00:00:00 2001 From: wylyl22 <2373073266@qq.com> Date: Mon, 8 Jan 2024 20:19:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/ui/chat/page/chat_kf_page.dart | 124 ++++++++++++++---- 1 file changed, 95 insertions(+), 29 deletions(-) diff --git a/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart b/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart index 033fc45..b49db65 100755 --- a/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart +++ b/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart @@ -1301,7 +1301,7 @@ class _ChatKFPageState extends State deleteListener: () async { Alert.dismiss(context); - bool canUseCamera = await PermissionTool.haveCameraPermission(); + bool canUseCamera = await PermissionTool.havePhotoPermission(); if (!canUseCamera) { PermissionTool.showOpenPermissionDialog( context, "没有相册使用权限,授予相册使用权限后才能上传素材"); @@ -1540,18 +1540,19 @@ class _ChatKFPageState extends State // 手机可以播放,但chrome无法播放 Future _pickVideo() async { try { + bool permission = await Permission.camera.isGranted; if (!permission) { Alert.show( context, NormalContentDialog( - title: '需要获取相机访问权限', + title: '需要获取相册访问权限', content: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ //Image.asset(R.ASSETS_LOCATION_PER_PNG,width: 44.rw,height: 44.rw,), Text( - '允许访问相机上传图片', + '允许访问相册上传视频', style: TextStyle(color: Color(0xFF666666), fontSize: 14), ), ], @@ -1564,10 +1565,10 @@ class _ChatKFPageState extends State deleteListener: () async { Alert.dismiss(context); - bool canUseCamera = await PermissionTool.haveCameraPermission(); + bool canUseCamera = await PermissionTool.havePhotoPermission(); if (!canUseCamera) { PermissionTool.showOpenPermissionDialog( - context, "没有相机使用权限,授予相机使用权限后才能上传素材"); + context, "没有相册使用权限,授予相册使用权限后才能上传素材"); } else{ XFile? pickedFile = await _picker.pickVideo( @@ -1616,31 +1617,96 @@ class _ChatKFPageState extends State // 录制视频 Future _captureVideo() async { try { - XFile? pickedFile = await _picker.pickVideo( - source: ImageSource.camera, maxDuration: const Duration(seconds: 10)); - // - if (pickedFile != null) { - BytedeskUtils.printLog('take video path: ${pickedFile.path}'); - // TODO: 将图片显示到对话消息中 - // TODO: 显示处理中loading - // 压缩 - // final info = await _flutterVideoCompress.compressVideo( - // pickedFile.path, - // quality: - // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) - // deleteOrigin: false, // default(false) - // ); - // // debugBytedeskUtils.printLog(info.toJson().toString()); - // String? afterPath = info.toJson()['path']; - // // BytedeskUtils.printLog('video path: ${pickedFile.path}, compress path: $afterPath'); - // // 上传 - // BlocProvider.of(context) - // ..add(UploadVideoEvent(filePath: afterPath)); - // - BlocProvider.of(context) - ..add(UploadVideoEvent(filePath: pickedFile.path)); + + bool permission = await Permission.camera.isGranted; + if (!permission) { + + Alert.show( + context, + NormalContentDialog( + title: '需要获取相机访问权限', + content: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + //Image.asset(R.ASSETS_LOCATION_PER_PNG,width: 44.rw,height: 44.rw,), + Text( + '允许访问相机上传图片', + style: TextStyle(color: Color(0xFF666666), fontSize: 14), + ), + ], + ), + items: ["残忍拒绝"], + listener: (index) { + Alert.dismiss(context); + }, + deleteItem: "立即授权", + deleteListener: () async { + Alert.dismiss(context); + + bool canUseCamera = await PermissionTool.haveCameraPermission(); + if (!canUseCamera) { + PermissionTool.showOpenPermissionDialog( + context, "没有相机使用权限,授予相机使用权限后才能上传素材"); + + } else{ + XFile? pickedFile = await _picker.pickVideo( + source: ImageSource.camera, maxDuration: const Duration(seconds: 10)); + // + if (pickedFile != null) { + BytedeskUtils.printLog('take video path: ${pickedFile.path}'); + // TODO: 将图片显示到对话消息中 + // TODO: 显示处理中loading + // 压缩 + // final info = await _flutterVideoCompress.compressVideo( + // pickedFile.path, + // quality: + // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) + // deleteOrigin: false, // default(false) + // ); + // // debugBytedeskUtils.printLog(info.toJson().toString()); + // String? afterPath = info.toJson()['path']; + // // BytedeskUtils.printLog('video path: ${pickedFile.path}, compress path: $afterPath'); + // // 上传 + // BlocProvider.of(context) + // ..add(UploadVideoEvent(filePath: afterPath)); + // + BlocProvider.of(context) + ..add(UploadVideoEvent(filePath: pickedFile.path)); + } else { + Fluttertoast.showToast(msg: '未录制视频'); + } + } + }, + type: NormalTextDialogType.delete, + ), + ); } else { - Fluttertoast.showToast(msg: '未录制视频'); + XFile? pickedFile = await _picker.pickVideo( + source: ImageSource.camera, maxDuration: const Duration(seconds: 10)); + // + if (pickedFile != null) { + BytedeskUtils.printLog('take video path: ${pickedFile.path}'); + // TODO: 将图片显示到对话消息中 + // TODO: 显示处理中loading + // 压缩 + // final info = await _flutterVideoCompress.compressVideo( + // pickedFile.path, + // quality: + // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) + // deleteOrigin: false, // default(false) + // ); + // // debugBytedeskUtils.printLog(info.toJson().toString()); + // String? afterPath = info.toJson()['path']; + // // BytedeskUtils.printLog('video path: ${pickedFile.path}, compress path: $afterPath'); + // // 上传 + // BlocProvider.of(context) + // ..add(UploadVideoEvent(filePath: afterPath)); + // + BlocProvider.of(context) + ..add(UploadVideoEvent(filePath: pickedFile.path)); + } else { + Fluttertoast.showToast(msg: '未录制视频'); + } } } catch (e) { BytedeskUtils.printLog('take video error ${e.toString()}');