fix: cached attachment image not showing on web

This commit is contained in:
Gordon Hayes
2022-11-17 16:19:04 +01:00
parent 6f0645d879
commit 0d6362e5d5
2 changed files with 37 additions and 15 deletions
@@ -56,22 +56,33 @@ class StreamImageAttachment extends StreamAttachmentWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return source.when( return source.when(
local: () { local: () {
if (attachment.localUri == null || attachment.file?.bytes == null) { if (attachment.file?.bytes != null) {
return AttachmentError(constraints: constraints); return _buildImageAttachment(
} context,
return _buildImageAttachment( Image.memory(
context, attachment.file!.bytes!,
Image.memory( height: constraints?.maxHeight,
attachment.file!.bytes!, width: constraints?.maxWidth,
height: constraints?.maxHeight, fit: BoxFit.cover,
width: constraints?.maxWidth, errorBuilder: _imageErrorBuilder,
fit: BoxFit.cover,
errorBuilder: (context, _, __) => Image.asset(
'images/placeholder.png',
package: 'stream_chat_flutter',
), ),
), );
); } else if (attachment.localUri != null) {
return _buildImageAttachment(
context,
Image.asset(
attachment.localUri!.path,
height: constraints?.maxHeight,
width: constraints?.maxWidth,
fit: BoxFit.cover,
errorBuilder: _imageErrorBuilder,
),
);
} else {
return AttachmentError(
constraints: constraints,
);
}
}, },
network: () { network: () {
var imageUrl = var imageUrl =
@@ -116,6 +127,12 @@ class StreamImageAttachment extends StreamAttachmentWidget {
); );
} }
Widget _imageErrorBuilder(BuildContext _, Object __, StackTrace? ___) =>
Image.asset(
'images/placeholder.png',
package: 'stream_chat_flutter',
);
Widget _buildImageAttachment(BuildContext context, Widget imageWidget) { Widget _buildImageAttachment(BuildContext context, Widget imageWidget) {
return Container( return Container(
constraints: constraints, constraints: constraints,
@@ -1,3 +1,8 @@
## Upcomming
🐞 Fixed
- [[#1379]](https://github.com/GetStream/stream-chat-flutter/issues/1379) Fixed "Issues with photo attachments on web", where the cached image attachment would not render while uploading.
-
## 5.1.0 ## 5.1.0
- Deprecated the `sort` parameter in the `StreamChannelListController` in favor of `channelStateSort`. - Deprecated the `sort` parameter in the `StreamChannelListController` in favor of `channelStateSort`.