Skip to content

Commit 3f24135

Browse files
authored
fix(ui): correctly save videos to gallery on mobile (#2386)
1 parent 1b93d73 commit 3f24135

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/stream_chat_flutter/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
🐞 Fixed
99

1010
- Fixed `.replaceMentions` not escaping special characters in the username.
11+
- Fixed videos not being saved to gallery correctly on mobile
12+
platforms. [[#2357]](https://github.com/GetStream/stream-chat-flutter/issues/2357)
1113
- Fixed unread indicator button using hardcoded white color instead of theme color
1214
`colorTheme.barsBg`. [[#2366]](https://github.com/GetStream/stream-chat-flutter/issues/2366)
1315
- Fixed `GradientAvatars` for users with same-length IDs would have identical

packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_io.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,19 @@ class StreamAttachmentHandler extends StreamAttachmentHandlerBase {
198198

199199
// Now that the file is saved, we need to copy it to the user's gallery
200200
// because the gallery only shows files that are in the gallery folder.
201-
await Gal.putImage(path);
201+
final copyToGallery = switch (file.mimeType) {
202+
final type? when type.startsWith('image/') => Gal.putImage,
203+
final type? when type.startsWith('video/') => Gal.putVideo,
204+
_ => null,
205+
};
202206

203-
// Once the file is copied to the gallery, we can delete the temporary file.
204-
await file.delete();
207+
if (copyToGallery != null) {
208+
await copyToGallery.call(path);
209+
210+
// If the file was successfully copied to the gallery, we can safely
211+
// delete the temporary file.
212+
await file.delete();
213+
}
205214

206215
return path;
207216
}

0 commit comments

Comments
 (0)