From f6c11b39794d5f870ea5235fe1e1aceebceb88d4 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 28 Jun 2023 14:28:00 +0530 Subject: [PATCH 1/2] fix(ui): save attachments to gallery. Signed-off-by: xsahil03x --- .../handler/stream_attachment_handler_io.dart | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_io.dart b/packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_io.dart index 1df1b411..e4d0b35e 100644 --- a/packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_io.dart +++ b/packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_io.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:file_picker/file_picker.dart'; import 'package:file_selector/file_selector.dart'; +import 'package:image_gallery_saver/image_gallery_saver.dart'; import 'package:image_picker/image_picker.dart'; import 'package:path_provider/path_provider.dart'; import 'package:stream_chat_flutter/src/attachment/handler/common.dart'; @@ -142,7 +143,6 @@ class StreamAttachmentHandler extends StreamAttachmentHandlerBase { final tempFilePath = tempPath .resolve(fileName!) .toFilePath(windows: CurrentPlatform.isWindows); - print(tempFilePath); final attachmentFileBytes = attachmentFile.bytes; if (attachmentFileBytes == null) { @@ -191,8 +191,26 @@ class StreamAttachmentHandler extends StreamAttachmentHandlerBase { // Create an XFile for proper file saving. final file = data.toXFile(path: path); - // Save the file to the user's selected path. + // Save the file to a temporary location. await file.saveTo(path); + + // Now that the file is saved, we need to copy it to the user's gallery + // because the gallery only shows files that are in the gallery folder. + await ImageGallerySaver.saveFile(path); + + // Once the file is copied to the gallery, we can delete the temporary file. + await file.delete(); + return path; } } + +extension on XFile { + /// Deletes this xfile from the file system. + Future delete() async { + final file = File(path); + if (file.existsSync()) { + await file.delete(); + } + } +} From 18e5b5406888061872e9ad50edacde51a07e2360 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 28 Jun 2023 14:42:08 +0530 Subject: [PATCH 2/2] chore: update CHANGELOG.md Signed-off-by: xsahil03x --- packages/stream_chat_flutter/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index ea75a9c8..d2ca7e28 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -11,6 +11,11 @@ and `SwipeDirection.endToStart` for other users. - [[#1590]](https://github.com/GetStream/stream-chat-flutter/issues/1590) Fixed `StreamMessageWidget.showReactionPickerIndicator` not toggling the reaction picker indicator visibility. +- [[#1639]](https://github.com/GetStream/stream-chat-flutter/issues/1639) Fixed attachments not showing in gallery view + even after saving them to the device. + > **Note** + > This fix depends on the [image_gallery_saver](https://pub.dev/packages/image_gallery_saver) plugin. Make sure to add + necessary permissions in your App as per the plugin documentation. ✅ Added @@ -79,6 +84,7 @@ }, ) ``` + - Deprecated `StreamMessageWidget.showReactionPickerIndicator` in favor of `StreamMessageWidget.showReactionPicker`. ```diff