diff --git a/lib/pages/dynamics/view.dart b/lib/pages/dynamics/view.dart index ee49ddf4..924a378e 100644 --- a/lib/pages/dynamics/view.dart +++ b/lib/pages/dynamics/view.dart @@ -550,30 +550,34 @@ class _CreatePanelState extends State { EasyThrottle.throttle( 'imagePicker', const Duration(milliseconds: 500), () async { - List pickedFiles = - await _imagePicker.pickMultiImage( - limit: _limit, - imageQuality: 100, - ); - if (pickedFiles.isNotEmpty) { - for (int i = 0; i < pickedFiles.length; i++) { - if (_pathList.length == _limit) { - SmartDialog.showToast('最多选择$_limit张图片'); - if (i != 0) { - _pathStream.add(_pathList); - } - break; - } else { - _pathList.add(pickedFiles[i].path); - if (i == pickedFiles.length - 1) { - _pathStream.add(_pathList); + try { + List pickedFiles = + await _imagePicker.pickMultiImage( + limit: _limit, + imageQuality: 100, + ); + if (pickedFiles.isNotEmpty) { + for (int i = 0; i < pickedFiles.length; i++) { + if (_pathList.length == _limit) { + SmartDialog.showToast('最多选择$_limit张图片'); + if (i != 0) { + _pathStream.add(_pathList); + } + break; + } else { + _pathList.add(pickedFiles[i].path); + if (i == pickedFiles.length - 1) { + _pathStream.add(_pathList); + } } } + if (_pathList.isNotEmpty && !_isEnable) { + _isEnable = true; + _isEnableStream.add(true); + } } - if (_pathList.isNotEmpty && !_isEnable) { - _isEnable = true; - _isEnableStream.add(true); - } + } catch (e) { + SmartDialog.showToast(e.toString()); } }); }, diff --git a/lib/pages/member/new/widget/edit_profile_page.dart b/lib/pages/member/new/widget/edit_profile_page.dart index cb424589..5eff4f93 100644 --- a/lib/pages/member/new/widget/edit_profile_page.dart +++ b/lib/pages/member/new/widget/edit_profile_page.dart @@ -448,67 +448,71 @@ class _EditProfilePageState extends State { } void _pickImg() async { - XFile? pickedFile = await _imagePicker.pickImage( - source: ImageSource.gallery, - imageQuality: 100, - ); - if (pickedFile != null && mounted) { - String? mimeType = - lookupMimeType(pickedFile.path)?.split('/').getOrNull(1); - if (mimeType == 'gif') { - SmartDialog.showToast('不能选GIF'); - return; - } - CroppedFile? croppedFile = await ImageCropper().cropImage( - sourcePath: pickedFile.path, - uiSettings: [ - AndroidUiSettings( - toolbarTitle: '裁剪', - toolbarColor: Theme.of(context).colorScheme.primary, - toolbarWidgetColor: Colors.white, - aspectRatioPresets: [ - CropAspectRatioPresetCustom(), - ], - lockAspectRatio: true, - hideBottomControls: true, - cropStyle: CropStyle.circle, - initAspectRatio: CropAspectRatioPresetCustom(), - ), - IOSUiSettings( - title: '裁剪', - aspectRatioPresets: [ - CropAspectRatioPresetCustom(), - ], - cropStyle: CropStyle.circle, - aspectRatioLockEnabled: true, - resetAspectRatioEnabled: false, - aspectRatioPickerButtonHidden: true, - ), - ], + try { + XFile? pickedFile = await _imagePicker.pickImage( + source: ImageSource.gallery, + imageQuality: 100, ); - if (croppedFile != null) { - Request() - .post( - '/x/member/web/face/update', - queryParameters: { - 'csrf': await Request.getCsrf(), - }, - data: FormData.fromMap({ - 'dopost': 'save', - 'DisplayRank': 10000, - 'face': await MultipartFile.fromFile(croppedFile.path), - }), - ) - .then((data) { - if (data.data['code'] == 0) { - (_loadingState as Success).response['face'] = data.data['data']; - SmartDialog.showToast('修改成功'); - setState(() {}); - } else { - SmartDialog.showToast(data.data['message']); - } - }); + if (pickedFile != null && mounted) { + String? mimeType = + lookupMimeType(pickedFile.path)?.split('/').getOrNull(1); + if (mimeType == 'gif') { + SmartDialog.showToast('不能选GIF'); + return; + } + CroppedFile? croppedFile = await ImageCropper().cropImage( + sourcePath: pickedFile.path, + uiSettings: [ + AndroidUiSettings( + toolbarTitle: '裁剪', + toolbarColor: Theme.of(context).colorScheme.primary, + toolbarWidgetColor: Colors.white, + aspectRatioPresets: [ + CropAspectRatioPresetCustom(), + ], + lockAspectRatio: true, + hideBottomControls: true, + cropStyle: CropStyle.circle, + initAspectRatio: CropAspectRatioPresetCustom(), + ), + IOSUiSettings( + title: '裁剪', + aspectRatioPresets: [ + CropAspectRatioPresetCustom(), + ], + cropStyle: CropStyle.circle, + aspectRatioLockEnabled: true, + resetAspectRatioEnabled: false, + aspectRatioPickerButtonHidden: true, + ), + ], + ); + if (croppedFile != null) { + Request() + .post( + '/x/member/web/face/update', + queryParameters: { + 'csrf': await Request.getCsrf(), + }, + data: FormData.fromMap({ + 'dopost': 'save', + 'DisplayRank': 10000, + 'face': await MultipartFile.fromFile(croppedFile.path), + }), + ) + .then((data) { + if (data.data['code'] == 0) { + (_loadingState as Success).response['face'] = data.data['data']; + SmartDialog.showToast('修改成功'); + setState(() {}); + } else { + SmartDialog.showToast(data.data['message']); + } + }); + } } + } catch (e) { + SmartDialog.showToast(e.toString()); } } } diff --git a/lib/pages/video/detail/introduction/widgets/create_fav_page.dart b/lib/pages/video/detail/introduction/widgets/create_fav_page.dart index 54f25879..712a919c 100644 --- a/lib/pages/video/detail/introduction/widgets/create_fav_page.dart +++ b/lib/pages/video/detail/introduction/widgets/create_fav_page.dart @@ -112,50 +112,54 @@ class _CreateFavPageState extends State { } void _pickImg() async { - XFile? pickedFile = await _imagePicker.pickImage( - source: ImageSource.gallery, - imageQuality: 100, - ); - if (pickedFile != null && mounted) { - CroppedFile? croppedFile = await ImageCropper().cropImage( - sourcePath: pickedFile.path, - uiSettings: [ - AndroidUiSettings( - toolbarTitle: '裁剪', - toolbarColor: Theme.of(context).colorScheme.primary, - toolbarWidgetColor: Colors.white, - aspectRatioPresets: [ - CropAspectRatioPreset.ratio16x9, - ], - lockAspectRatio: true, - hideBottomControls: true, - initAspectRatio: CropAspectRatioPreset.ratio16x9, - ), - IOSUiSettings( - title: '裁剪', - aspectRatioPresets: [ - CropAspectRatioPreset.ratio16x9, - ], - aspectRatioLockEnabled: true, - resetAspectRatioEnabled: false, - aspectRatioPickerButtonHidden: true, - ), - ], + try { + XFile? pickedFile = await _imagePicker.pickImage( + source: ImageSource.gallery, + imageQuality: 100, ); - if (croppedFile != null) { - MsgHttp.uploadImage( - path: croppedFile.path, - bucket: 'medialist', - dir: 'cover', - ).then((data) { - if (data['status']) { - _cover = data['data']['location']; - setState(() {}); - } else { - SmartDialog.showToast(data['msg']); - } - }); + if (pickedFile != null && mounted) { + CroppedFile? croppedFile = await ImageCropper().cropImage( + sourcePath: pickedFile.path, + uiSettings: [ + AndroidUiSettings( + toolbarTitle: '裁剪', + toolbarColor: Theme.of(context).colorScheme.primary, + toolbarWidgetColor: Colors.white, + aspectRatioPresets: [ + CropAspectRatioPreset.ratio16x9, + ], + lockAspectRatio: true, + hideBottomControls: true, + initAspectRatio: CropAspectRatioPreset.ratio16x9, + ), + IOSUiSettings( + title: '裁剪', + aspectRatioPresets: [ + CropAspectRatioPreset.ratio16x9, + ], + aspectRatioLockEnabled: true, + resetAspectRatioEnabled: false, + aspectRatioPickerButtonHidden: true, + ), + ], + ); + if (croppedFile != null) { + MsgHttp.uploadImage( + path: croppedFile.path, + bucket: 'medialist', + dir: 'cover', + ).then((data) { + if (data['status']) { + _cover = data['data']['location']; + setState(() {}); + } else { + SmartDialog.showToast(data['msg']); + } + }); + } } + } catch (e) { + SmartDialog.showToast(e.toString()); } } diff --git a/lib/pages/video/detail/reply_new/reply_page.dart b/lib/pages/video/detail/reply_new/reply_page.dart index 3a2c712b..2760f6c0 100644 --- a/lib/pages/video/detail/reply_new/reply_page.dart +++ b/lib/pages/video/detail/reply_new/reply_page.dart @@ -361,27 +361,31 @@ class _ReplyPageState extends State EasyThrottle.throttle( 'imagePicker', const Duration(milliseconds: 500), () async { - List pickedFiles = - await _imagePicker.pickMultiImage( - limit: _limit, - imageQuality: 100, - ); - if (pickedFiles.isNotEmpty) { - for (int i = 0; i < pickedFiles.length; i++) { - if (_pathList.length == _limit) { - SmartDialog.showToast('最多选择$_limit张图片'); - if (i != 0) { - _pathStream.add(_pathList); - } - break; - } else { - _pathList.add(pickedFiles[i].path); - if (i == pickedFiles.length - 1) { - SmartDialog.dismiss(); - _pathStream.add(_pathList); + try { + List pickedFiles = + await _imagePicker.pickMultiImage( + limit: _limit, + imageQuality: 100, + ); + if (pickedFiles.isNotEmpty) { + for (int i = 0; i < pickedFiles.length; i++) { + if (_pathList.length == _limit) { + SmartDialog.showToast('最多选择$_limit张图片'); + if (i != 0) { + _pathStream.add(_pathList); + } + break; + } else { + _pathList.add(pickedFiles[i].path); + if (i == pickedFiles.length - 1) { + SmartDialog.dismiss(); + _pathStream.add(_pathList); + } } } } + } catch (e) { + SmartDialog.showToast(e.toString()); } }); }, diff --git a/lib/pages/whisper_detail/view.dart b/lib/pages/whisper_detail/view.dart index 66c5b9d8..ae255f73 100644 --- a/lib/pages/whisper_detail/view.dart +++ b/lib/pages/whisper_detail/view.dart @@ -310,37 +310,42 @@ class _WhisperDetailPageState extends State { if (snapshot.data == true) { _whisperDetailController.sendMsg(); } else { - XFile? pickedFile = await _imagePicker.pickImage( - source: ImageSource.gallery, - imageQuality: 100, - ); - if (pickedFile != null) { - SmartDialog.showLoading(msg: '正在上传图片'); - dynamic result = await MsgHttp.uploadBfs( - path: pickedFile.path, - biz: 'im', + try { + XFile? pickedFile = await _imagePicker.pickImage( + source: ImageSource.gallery, + imageQuality: 100, ); - if (result['status']) { - int imageSize = await File(pickedFile.path).length(); - String mimeType = lookupMimeType(pickedFile.path) - ?.split('/') - .getOrNull(1) ?? - 'png'; - dynamic picMsg = { - 'url': result['data']['image_url'], - 'height': result['data']['image_height'], - 'width': result['data']['image_width'], - 'imageType': mimeType, - 'original': 1, - 'size': imageSize / 1024, - }; - SmartDialog.showLoading(msg: '正在发送'); - await _whisperDetailController.sendMsg(picMsg: picMsg); - } else { - SmartDialog.dismiss(); - SmartDialog.showToast(result['msg']); - return; + if (pickedFile != null) { + SmartDialog.showLoading(msg: '正在上传图片'); + dynamic result = await MsgHttp.uploadBfs( + path: pickedFile.path, + biz: 'im', + ); + if (result['status']) { + int imageSize = await File(pickedFile.path).length(); + String mimeType = lookupMimeType(pickedFile.path) + ?.split('/') + .getOrNull(1) ?? + 'png'; + dynamic picMsg = { + 'url': result['data']['image_url'], + 'height': result['data']['image_height'], + 'width': result['data']['image_width'], + 'imageType': mimeType, + 'original': 1, + 'size': imageSize / 1024, + }; + SmartDialog.showLoading(msg: '正在发送'); + await _whisperDetailController.sendMsg( + picMsg: picMsg); + } else { + SmartDialog.dismiss(); + SmartDialog.showToast(result['msg']); + return; + } } + } catch (e) { + SmartDialog.showToast(e.toString()); } } },