[MessageWidget] Fix attachment padding and border sides

Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
Sahil Kumar
2021-01-13 15:09:28 +05:30
parent 987f6991fe
commit 3432b7c5ee
3 changed files with 45 additions and 51 deletions
+1 -9
View File
@@ -62,15 +62,7 @@ class _FileAttachmentState extends State<FileAttachment> {
child: Container(
width: widget.size?.width ?? 100,
height: 56.0,
decoration: BoxDecoration(
color: StreamChatTheme.of(context).colorTheme.white,
borderRadius:
widget.trailing != null ? BorderRadius.circular(16.0) : null,
border: widget.trailing != null
? Border.fromBorderSide(BorderSide(
color: StreamChatTheme.of(context).colorTheme.greyWhisper))
: null,
),
color: StreamChatTheme.of(context).colorTheme.white,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
+6 -3
View File
@@ -815,7 +815,9 @@ class _MessageListViewState extends State<MessageListView> {
message.attachments?.any((it) => it.ogScrapeUrl != null) == true;
final borderSide =
isOnlyEmoji || hasUrlAttachment || isMyMessage ? BorderSide.none : null;
isOnlyEmoji || hasUrlAttachment || (isMyMessage && !hasFileAttachment)
? BorderSide.none
: null;
Widget child = MessageWidget(
key: ValueKey<String>('MESSAGE-${message.id}'),
@@ -859,14 +861,15 @@ class _MessageListViewState extends State<MessageListView> {
attachmentBorderRadiusGeometry: BorderRadius.only(
topLeft: Radius.circular(attachmentBorderRadius),
bottomLeft: Radius.circular(
(timeDiff >= 1 || !isNextUserSame) && !(hasReplies || isThreadMessage)
(timeDiff >= 1 || !isNextUserSame) &&
!(hasReplies || isThreadMessage || hasFileAttachment)
? 0
: attachmentBorderRadius,
),
topRight: Radius.circular(attachmentBorderRadius),
bottomRight: Radius.circular(attachmentBorderRadius),
),
attachmentPadding: const EdgeInsets.all(2),
attachmentPadding: EdgeInsets.all(hasFileAttachment ? 4 : 2),
borderRadiusGeometry: BorderRadius.only(
topLeft: Radius.circular(16),
bottomLeft: Radius.circular(
+38 -39
View File
@@ -419,7 +419,7 @@ class _MessageWidgetState extends State<MessageWidget> {
if (hasQuotedMessage)
_buildQuotedMessage(),
if (hasNonUrlAttachments)
..._parseAttachments(
_parseAttachments(
context),
if (widget.message.text
.trim()
@@ -777,7 +777,7 @@ class _MessageWidgetState extends State<MessageWidget> {
side: widget.attachmentBorderSide ??
widget.borderSide ??
BorderSide(
color: StreamChatTheme.of(context).colorTheme.greyGainsboro,
color: StreamChatTheme.of(context).colorTheme.greyWhisper,
),
borderRadius: widget.attachmentBorderRadiusGeometry ??
widget.borderRadiusGeometry ??
@@ -785,7 +785,7 @@ class _MessageWidgetState extends State<MessageWidget> {
);
}
List<Widget> _parseAttachments(BuildContext context) {
Widget _parseAttachments(BuildContext context) {
final images = widget.message.attachments
?.where((element) =>
element.type == 'image' && element.ogScrapeUrl == null)
@@ -793,8 +793,9 @@ class _MessageWidgetState extends State<MessageWidget> {
[];
if (images.length > 1) {
return [
wrapAttachmentWidget(
return Padding(
padding: widget.attachmentPadding,
child: wrapAttachmentWidget(
context,
Material(
color: widget.messageTheme.messageBackgroundColor,
@@ -809,30 +810,36 @@ class _MessageWidgetState extends State<MessageWidget> {
),
),
),
];
);
}
return widget.message.attachments
?.where((element) => element.ogScrapeUrl == null)
?.map((attachment) {
final attachmentBuilder = widget.attachmentBuilders[attachment.type];
return Padding(
padding: widget.attachmentPadding,
child: Column(
mainAxisSize: MainAxisSize.min,
children: widget.message.attachments
?.where((element) => element.ogScrapeUrl == null)
?.map((attachment) {
final attachmentBuilder =
widget.attachmentBuilders[attachment.type];
if (attachmentBuilder == null) {
return SizedBox();
}
final attachmentWidget = attachmentBuilder(
context,
widget.message,
attachment,
);
return wrapAttachmentWidget(
context,
attachmentWidget,
attachment: attachment,
);
})?.toList() ??
[];
if (attachmentBuilder == null) return SizedBox();
final attachmentWidget = attachmentBuilder(
context,
widget.message,
attachment,
);
return wrapAttachmentWidget(
context,
attachmentWidget,
attachment: attachment,
);
})?.insertBetween(SizedBox(
height: widget.attachmentPadding.vertical / 2,
)) ??
[],
),
);
}
Widget wrapAttachmentWidget(
@@ -843,21 +850,13 @@ class _MessageWidgetState extends State<MessageWidget> {
final attachmentShape =
widget.attachmentShape ?? widget.shape ?? _getDefaultShape(context);
return Material(
color: _getBackgroundColor(),
clipBehavior: Clip.antiAlias,
shape: attachmentShape,
child: Padding(
padding: widget.attachmentPadding,
child: Material(
clipBehavior: Clip.hardEdge,
shape: attachmentShape,
type: MaterialType.transparency,
child: Transform(
transform: Matrix4.rotationY(widget.reverse ? pi : 0),
alignment: Alignment.center,
child: attachmentWidget,
),
),
type: MaterialType.transparency,
child: Transform(
transform: Matrix4.rotationY(widget.reverse ? pi : 0),
alignment: Alignment.center,
child: attachmentWidget,
),
);
}