Merge pull request #1640 from GetStream/fix/save-to-gallery

This commit is contained in:
Sahil Kumar
2023-06-28 15:04:21 +05:30
committed by GitHub
2 changed files with 26 additions and 2 deletions
@@ -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
@@ -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<void> delete() async {
final file = File(path);
if (file.existsSync()) {
await file.delete();
}
}
}