fix thumbnails
This commit is contained in:
@@ -730,12 +730,18 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
|
|
||||||
void _addAttachment(Media medium) async {
|
void _addAttachment(Media medium) async {
|
||||||
final mediaFile = await medium.getFile();
|
final mediaFile = await medium.getFile();
|
||||||
|
final thumbBytes = await medium.getThumbnail();
|
||||||
|
|
||||||
final file = PlatformFile(
|
final file = PlatformFile(
|
||||||
path: mediaFile.path,
|
path: mediaFile.path,
|
||||||
bytes: mediaFile.readAsBytesSync(),
|
bytes: mediaFile.readAsBytesSync(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final thumbFile = PlatformFile(
|
||||||
|
bytes: thumbBytes,
|
||||||
|
name: '${file.name ?? file.path?.split('/')?.last}_thumbnail.jpeg',
|
||||||
|
);
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_inputEnabled = true;
|
_inputEnabled = true;
|
||||||
});
|
});
|
||||||
@@ -747,6 +753,7 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
final channel = StreamChannel.of(context).channel;
|
final channel = StreamChannel.of(context).channel;
|
||||||
final attachment = _SendingAttachment(
|
final attachment = _SendingAttachment(
|
||||||
file: file,
|
file: file,
|
||||||
|
thumbFile: thumbFile,
|
||||||
attachment: Attachment(
|
attachment: Attachment(
|
||||||
localUri: file.path != null ? Uri.parse(file.path) : null,
|
localUri: file.path != null ? Uri.parse(file.path) : null,
|
||||||
type: medium.mediaType == MediaType.image ? 'image' : 'video',
|
type: medium.mediaType == MediaType.image ? 'image' : 'video',
|
||||||
@@ -758,6 +765,11 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
_attachments.add(attachment);
|
_attachments.add(attachment);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final thumbUrl = await _uploadImage(
|
||||||
|
thumbFile,
|
||||||
|
channel,
|
||||||
|
);
|
||||||
|
|
||||||
final url = await _uploadAttachment(
|
final url = await _uploadAttachment(
|
||||||
file,
|
file,
|
||||||
medium.mediaType == MediaType.image
|
medium.mediaType == MediaType.image
|
||||||
@@ -772,10 +784,12 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
if (fileType == DefaultAttachmentTypes.image) {
|
if (fileType == DefaultAttachmentTypes.image) {
|
||||||
attachment.attachment = attachment.attachment.copyWith(
|
attachment.attachment = attachment.attachment.copyWith(
|
||||||
imageUrl: url,
|
imageUrl: url,
|
||||||
|
thumbUrl: thumbUrl,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
attachment.attachment = attachment.attachment.copyWith(
|
attachment.attachment = attachment.attachment.copyWith(
|
||||||
assetUrl: url,
|
assetUrl: url,
|
||||||
|
thumbUrl: thumbUrl,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1041,7 +1055,7 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
return _attachments.isEmpty
|
return _attachments.isEmpty
|
||||||
? Container()
|
? Container()
|
||||||
: LimitedBox(
|
: LimitedBox(
|
||||||
maxHeight: 76.0,
|
maxHeight: 104.0,
|
||||||
child: ListView(
|
child: ListView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
children: _attachments
|
children: _attachments
|
||||||
@@ -1055,8 +1069,8 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
AspectRatio(
|
AspectRatio(
|
||||||
aspectRatio: 1.0,
|
aspectRatio: 1.0,
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 50,
|
height: 104,
|
||||||
width: 50,
|
width: 104,
|
||||||
child: _buildAttachment(attachment),
|
child: _buildAttachment(attachment),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -1138,9 +1152,26 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'video':
|
case 'video':
|
||||||
return Container(
|
return Stack(
|
||||||
child: Icon(Icons.videocam),
|
children: [
|
||||||
color: Colors.black26,
|
Container(
|
||||||
|
child: attachment.thumbFile != null
|
||||||
|
? Image.memory(
|
||||||
|
attachment.thumbFile.bytes,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
)
|
||||||
|
: Icon(Icons.videocam),
|
||||||
|
color: Colors.black26,
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
left: 8,
|
||||||
|
bottom: 10,
|
||||||
|
child: SvgPicture.asset(
|
||||||
|
'svgs/video_call_icon.svg',
|
||||||
|
package: 'stream_chat_flutter',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -1426,7 +1457,9 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
MultipartFile.fromBytes(
|
MultipartFile.fromBytes(
|
||||||
bytes,
|
bytes,
|
||||||
filename: filename,
|
filename: filename,
|
||||||
contentType: httpParser.MediaType.parse(lookupMimeType(filename)),
|
contentType: filename != null
|
||||||
|
? httpParser.MediaType.parse(lookupMimeType(filename))
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
return res.file;
|
return res.file;
|
||||||
@@ -1657,12 +1690,14 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
|
|
||||||
class _SendingAttachment {
|
class _SendingAttachment {
|
||||||
PlatformFile file;
|
PlatformFile file;
|
||||||
|
PlatformFile thumbFile;
|
||||||
Attachment attachment;
|
Attachment attachment;
|
||||||
bool uploaded;
|
bool uploaded;
|
||||||
String id;
|
String id;
|
||||||
|
|
||||||
_SendingAttachment({
|
_SendingAttachment({
|
||||||
this.file,
|
this.file,
|
||||||
|
this.thumbFile,
|
||||||
this.attachment,
|
this.attachment,
|
||||||
this.uploaded = false,
|
this.uploaded = false,
|
||||||
this.id,
|
this.id,
|
||||||
|
|||||||
+16
-18
@@ -38,25 +38,23 @@ class UserAvatar extends StatelessWidget {
|
|||||||
: null,
|
: null,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
ClipRRect(
|
Container(
|
||||||
borderRadius: borderRadius ??
|
constraints: constraints ??
|
||||||
streamChatTheme.ownMessageTheme.avatarTheme.borderRadius,
|
streamChatTheme.ownMessageTheme.avatarTheme.constraints,
|
||||||
child: Container(
|
clipBehavior: Clip.antiAlias,
|
||||||
constraints: constraints ??
|
decoration: BoxDecoration(
|
||||||
streamChatTheme.ownMessageTheme.avatarTheme.constraints,
|
borderRadius: borderRadius ??
|
||||||
decoration: BoxDecoration(
|
streamChatTheme.ownMessageTheme.avatarTheme.borderRadius,
|
||||||
color: streamChatTheme.accentColor,
|
color: streamChatTheme.accentColor,
|
||||||
),
|
|
||||||
child: hasImage
|
|
||||||
? CachedNetworkImage(
|
|
||||||
imageUrl: user.extraData['image'],
|
|
||||||
errorWidget: (_, __, ___) {
|
|
||||||
return streamChatTheme.defaultUserImage(context, user);
|
|
||||||
},
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
)
|
|
||||||
: streamChatTheme.defaultUserImage(context, user),
|
|
||||||
),
|
),
|
||||||
|
child: hasImage
|
||||||
|
? CachedNetworkImage(
|
||||||
|
imageUrl: user.extraData['image'],
|
||||||
|
errorWidget: (_, __, ___) {
|
||||||
|
return streamChatTheme.defaultUserImage(context, user);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: streamChatTheme.defaultUserImage(context, user),
|
||||||
),
|
),
|
||||||
if (showOnlineStatus && user.online == true)
|
if (showOnlineStatus && user.online == true)
|
||||||
Positioned(
|
Positioned(
|
||||||
|
|||||||
Reference in New Issue
Block a user