From b8f5cc82f953aa84fdc810d7cff10652130bf856 Mon Sep 17 00:00:00 2001 From: LittleSheep <littlesheep.code@hotmail.com> Date: Thu, 20 Mar 2025 23:20:24 +0800 Subject: [PATCH] :sparkles: Add attachments from file --- assets/translations/en-US.json | 1 + assets/translations/zh-CN.json | 1 + assets/translations/zh-HK.json | 1 + assets/translations/zh-TW.json | 1 + ios/Runner/Info.plist | 2 ++ lib/widgets/post/post_media_pending_list.dart | 21 +++++++++++++++++++ macos/Runner/Info.plist | 2 ++ 7 files changed, 29 insertions(+) diff --git a/assets/translations/en-US.json b/assets/translations/en-US.json index c1c4f7b..b3a25fa 100644 --- a/assets/translations/en-US.json +++ b/assets/translations/en-US.json @@ -338,6 +338,7 @@ "fieldAttachmentRandomId": "Random ID", "fieldAttachmentAlt": "Alternative text", "addAttachmentFromAlbum": "Add from album", + "addAttachmentFromFiles": "Add from files", "addAttachmentFromClipboard": "Paste file", "addAttachmentFromCameraPhoto": "Take photo", "addAttachmentFromCameraVideo": "Take video", diff --git a/assets/translations/zh-CN.json b/assets/translations/zh-CN.json index ebfd27a..3c3079c 100644 --- a/assets/translations/zh-CN.json +++ b/assets/translations/zh-CN.json @@ -336,6 +336,7 @@ "fieldAttachmentRandomId": "访问 ID", "fieldAttachmentAlt": "概述文字", "addAttachmentFromAlbum": "从相册中添加附件", + "addAttachmentFromFiles": "从文件中添加附件", "addAttachmentFromClipboard": "粘贴附件", "addAttachmentFromCameraPhoto": "拍摄照片", "addAttachmentFromCameraVideo": "拍摄视频", diff --git a/assets/translations/zh-HK.json b/assets/translations/zh-HK.json index 0636722..13ab3ad 100644 --- a/assets/translations/zh-HK.json +++ b/assets/translations/zh-HK.json @@ -336,6 +336,7 @@ "fieldAttachmentRandomId": "訪問 ID", "fieldAttachmentAlt": "概述文字", "addAttachmentFromAlbum": "從相冊中添加附件", + "addAttachmentFromFiles": "從文件中添加附件", "addAttachmentFromClipboard": "粘貼附件", "addAttachmentFromCameraPhoto": "拍攝照片", "addAttachmentFromCameraVideo": "拍攝視頻", diff --git a/assets/translations/zh-TW.json b/assets/translations/zh-TW.json index 702b2c0..b85aefa 100644 --- a/assets/translations/zh-TW.json +++ b/assets/translations/zh-TW.json @@ -336,6 +336,7 @@ "fieldAttachmentRandomId": "訪問 ID", "fieldAttachmentAlt": "概述文字", "addAttachmentFromAlbum": "從相冊中添加附件", + "addAttachmentFromFiles": "從文件中添加附件", "addAttachmentFromClipboard": "粘貼附件", "addAttachmentFromCameraPhoto": "拍攝照片", "addAttachmentFromCameraVideo": "拍攝視頻", diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index f13faaa..4b93f1c 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -79,6 +79,8 @@ <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array> + <key>LSSupportsOpeningDocumentsInPlace</key> + <true/> <key>UISupportedInterfaceOrientations~ipad</key> <array> <string>UIInterfaceOrientationPortrait</string> diff --git a/lib/widgets/post/post_media_pending_list.dart b/lib/widgets/post/post_media_pending_list.dart index 9a6fa1a..60a7bd0 100644 --- a/lib/widgets/post/post_media_pending_list.dart +++ b/lib/widgets/post/post_media_pending_list.dart @@ -4,6 +4,7 @@ import 'dart:ui'; import 'package:croppy/croppy.dart'; import 'package:dismissible_page/dismissible_page.dart'; import 'package:easy_localization/easy_localization.dart'; +import 'package:file_picker/file_picker.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -491,6 +492,14 @@ class AddPostMediaButton extends StatelessWidget { ); } + void _selectFile() async { + final result = await FilePicker.platform.pickFiles(type: FileType.any); + if (result == null) return; + onAdd( + result.files.map((e) => PostWriteMedia.fromFile(e.xFile)), + ); + } + void _pasteMedia() async { final imageBytes = await Pasteboard.image; if (imageBytes == null) return; @@ -605,6 +614,18 @@ class AddPostMediaButton extends StatelessWidget { _selectMedia(); }, ), + PopupMenuItem( + child: Row( + children: [ + const Icon(Symbols.file_upload), + const Gap(16), + Text('addAttachmentFromFiles').tr(), + ], + ), + onTap: () { + _selectFile(); + }, + ), PopupMenuItem( child: Row( children: [ diff --git a/macos/Runner/Info.plist b/macos/Runner/Info.plist index 5968128..27783a1 100644 --- a/macos/Runner/Info.plist +++ b/macos/Runner/Info.plist @@ -2,6 +2,8 @@ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> + <key>LSSupportsOpeningDocumentsInPlace</key> + <true/> <key>CFBundleDevelopmentRegion</key> <string>$(DEVELOPMENT_LANGUAGE)</string> <key>CFBundleExecutable</key>