[MessageWidget] Separate our default messageShape and attachmentShape
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -32,6 +32,7 @@ class MessageActionsModal extends StatefulWidget {
|
|||||||
final bool showFlagButton;
|
final bool showFlagButton;
|
||||||
final bool reverse;
|
final bool reverse;
|
||||||
final ShapeBorder messageShape;
|
final ShapeBorder messageShape;
|
||||||
|
final ShapeBorder attachmentShape;
|
||||||
final DisplayWidget showUserAvatar;
|
final DisplayWidget showUserAvatar;
|
||||||
|
|
||||||
const MessageActionsModal({
|
const MessageActionsModal({
|
||||||
@@ -51,6 +52,7 @@ class MessageActionsModal extends StatefulWidget {
|
|||||||
this.showUserAvatar = DisplayWidget.show,
|
this.showUserAvatar = DisplayWidget.show,
|
||||||
this.editMessageInputBuilder,
|
this.editMessageInputBuilder,
|
||||||
this.messageShape,
|
this.messageShape,
|
||||||
|
this.attachmentShape,
|
||||||
this.reverse = false,
|
this.reverse = false,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@@ -173,6 +175,7 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
|
|||||||
showInChannelIndicator: false,
|
showInChannelIndicator: false,
|
||||||
showSendingIndicator: false,
|
showSendingIndicator: false,
|
||||||
shape: widget.messageShape,
|
shape: widget.messageShape,
|
||||||
|
attachmentShape: widget.attachmentShape,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 8),
|
SizedBox(height: 8),
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ class MessageReactionsModal extends StatelessWidget {
|
|||||||
final bool showReactions;
|
final bool showReactions;
|
||||||
final DisplayWidget showUserAvatar;
|
final DisplayWidget showUserAvatar;
|
||||||
final ShapeBorder messageShape;
|
final ShapeBorder messageShape;
|
||||||
|
final ShapeBorder attachmentShape;
|
||||||
final void Function(User) onUserAvatarTap;
|
final void Function(User) onUserAvatarTap;
|
||||||
|
|
||||||
const MessageReactionsModal({
|
const MessageReactionsModal({
|
||||||
@@ -30,6 +31,7 @@ class MessageReactionsModal extends StatelessWidget {
|
|||||||
this.onThreadTap,
|
this.onThreadTap,
|
||||||
this.editMessageInputBuilder,
|
this.editMessageInputBuilder,
|
||||||
this.messageShape,
|
this.messageShape,
|
||||||
|
this.attachmentShape,
|
||||||
this.reverse = false,
|
this.reverse = false,
|
||||||
this.showUserAvatar = DisplayWidget.show,
|
this.showUserAvatar = DisplayWidget.show,
|
||||||
this.onUserAvatarTap,
|
this.onUserAvatarTap,
|
||||||
@@ -127,6 +129,7 @@ class MessageReactionsModal extends StatelessWidget {
|
|||||||
translateUserAvatar: false,
|
translateUserAvatar: false,
|
||||||
showSendingIndicator: false,
|
showSendingIndicator: false,
|
||||||
shape: messageShape,
|
shape: messageShape,
|
||||||
|
attachmentShape: attachmentShape,
|
||||||
padding: const EdgeInsets.all(0),
|
padding: const EdgeInsets.all(0),
|
||||||
attachmentPadding: EdgeInsets.all(
|
attachmentPadding: EdgeInsets.all(
|
||||||
hasFileAttachment ? 4 : 2,
|
hasFileAttachment ? 4 : 2,
|
||||||
|
|||||||
+41
-39
@@ -295,10 +295,6 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
var leftPadding =
|
var leftPadding =
|
||||||
widget.showUserAvatar != DisplayWidget.gone ? avatarWidth + 8.5 : 0.5;
|
widget.showUserAvatar != DisplayWidget.gone ? avatarWidth + 8.5 : 0.5;
|
||||||
|
|
||||||
final hasFiles =
|
|
||||||
widget.message.attachments?.any((element) => element.type == 'file') ==
|
|
||||||
true;
|
|
||||||
|
|
||||||
return Material(
|
return Material(
|
||||||
type: MaterialType.transparency,
|
type: MaterialType.transparency,
|
||||||
child: Portal(
|
child: Portal(
|
||||||
@@ -406,29 +402,19 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
BorderRadius.zero,
|
BorderRadius.zero,
|
||||||
),
|
),
|
||||||
color: _getBackgroundColor(),
|
color: _getBackgroundColor(),
|
||||||
child: Padding(
|
child: Column(
|
||||||
padding: EdgeInsets.all(
|
crossAxisAlignment:
|
||||||
hasFiles ? 2.0 : 0.0),
|
CrossAxisAlignment.end,
|
||||||
child: Column(
|
mainAxisSize:
|
||||||
crossAxisAlignment:
|
MainAxisSize.min,
|
||||||
CrossAxisAlignment
|
children: <Widget>[
|
||||||
.end,
|
if (hasQuotedMessage)
|
||||||
mainAxisSize:
|
_buildQuotedMessage(),
|
||||||
MainAxisSize.min,
|
if (hasNonUrlAttachments)
|
||||||
children: <Widget>[
|
_parseAttachments(),
|
||||||
if (hasQuotedMessage)
|
if (!isGiphy)
|
||||||
_buildQuotedMessage(),
|
_buildTextBubble(),
|
||||||
if (hasNonUrlAttachments)
|
],
|
||||||
_parseAttachments(
|
|
||||||
context),
|
|
||||||
if (widget.message.text
|
|
||||||
.trim()
|
|
||||||
.isNotEmpty &&
|
|
||||||
!isGiphy)
|
|
||||||
_buildTextBubble(
|
|
||||||
context),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -718,6 +704,8 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
: DisplayWidget.show,
|
: DisplayWidget.show,
|
||||||
messageTheme: widget.messageTheme,
|
messageTheme: widget.messageTheme,
|
||||||
messageShape: widget.shape ?? _getDefaultShape(context),
|
messageShape: widget.shape ?? _getDefaultShape(context),
|
||||||
|
attachmentShape:
|
||||||
|
widget.attachmentShape ?? _getDefaultAttachmentShape(context),
|
||||||
reverse: widget.reverse,
|
reverse: widget.reverse,
|
||||||
showDeleteMessage: widget.showDeleteMessage || isDeleteFailed,
|
showDeleteMessage: widget.showDeleteMessage || isDeleteFailed,
|
||||||
message: widget.message,
|
message: widget.message,
|
||||||
@@ -763,6 +751,8 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
onUserAvatarTap: widget.onUserAvatarTap,
|
onUserAvatarTap: widget.onUserAvatarTap,
|
||||||
messageTheme: widget.messageTheme,
|
messageTheme: widget.messageTheme,
|
||||||
messageShape: widget.shape ?? _getDefaultShape(context),
|
messageShape: widget.shape ?? _getDefaultShape(context),
|
||||||
|
attachmentShape:
|
||||||
|
widget.attachmentShape ?? _getDefaultAttachmentShape(context),
|
||||||
reverse: widget.reverse,
|
reverse: widget.reverse,
|
||||||
message: widget.message,
|
message: widget.message,
|
||||||
editMessageInputBuilder: widget.editMessageInputBuilder,
|
editMessageInputBuilder: widget.editMessageInputBuilder,
|
||||||
@@ -773,20 +763,31 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapeBorder _getDefaultShape(BuildContext context) {
|
ShapeBorder _getDefaultAttachmentShape(BuildContext context) {
|
||||||
|
final hasFiles =
|
||||||
|
widget.message.attachments?.any((it) => it.type == 'file') == true;
|
||||||
return RoundedRectangleBorder(
|
return RoundedRectangleBorder(
|
||||||
side: widget.attachmentBorderSide ??
|
side: hasFiles
|
||||||
widget.borderSide ??
|
? widget.attachmentBorderSide ??
|
||||||
BorderSide(
|
BorderSide(
|
||||||
color: StreamChatTheme.of(context).colorTheme.greyWhisper,
|
color: StreamChatTheme.of(context).colorTheme.greyWhisper,
|
||||||
),
|
)
|
||||||
borderRadius: widget.attachmentBorderRadiusGeometry ??
|
: BorderSide.none,
|
||||||
widget.borderRadiusGeometry ??
|
borderRadius: widget.attachmentBorderRadiusGeometry ?? BorderRadius.zero,
|
||||||
BorderRadius.zero,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _parseAttachments(BuildContext context) {
|
ShapeBorder _getDefaultShape(BuildContext context) {
|
||||||
|
return RoundedRectangleBorder(
|
||||||
|
side: widget.borderSide ??
|
||||||
|
BorderSide(
|
||||||
|
color: StreamChatTheme.of(context).colorTheme.greyWhisper,
|
||||||
|
),
|
||||||
|
borderRadius: widget.borderRadiusGeometry ?? BorderRadius.zero,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _parseAttachments() {
|
||||||
final images = widget.message.attachments
|
final images = widget.message.attachments
|
||||||
?.where((element) =>
|
?.where((element) =>
|
||||||
element.type == 'image' && element.ogScrapeUrl == null)
|
element.type == 'image' && element.ogScrapeUrl == null)
|
||||||
@@ -849,7 +850,7 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
Attachment attachment,
|
Attachment attachment,
|
||||||
}) {
|
}) {
|
||||||
final attachmentShape =
|
final attachmentShape =
|
||||||
widget.attachmentShape ?? widget.shape ?? _getDefaultShape(context);
|
widget.attachmentShape ?? _getDefaultAttachmentShape(context);
|
||||||
return Material(
|
return Material(
|
||||||
clipBehavior: Clip.antiAlias,
|
clipBehavior: Clip.antiAlias,
|
||||||
shape: attachmentShape,
|
shape: attachmentShape,
|
||||||
@@ -920,7 +921,8 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Widget _buildTextBubble(BuildContext context) {
|
Widget _buildTextBubble() {
|
||||||
|
if (widget.message.text.trim().isNotEmpty) return Offstage();
|
||||||
return Transform(
|
return Transform(
|
||||||
transform: Matrix4.rotationY(widget.reverse ? pi : 0),
|
transform: Matrix4.rotationY(widget.reverse ? pi : 0),
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
|
|||||||
Reference in New Issue
Block a user