From 596d7292232c8c9be414c5bfe033d7d4b08d984e Mon Sep 17 00:00:00 2001 From: Bravo Date: Mon, 1 Jul 2024 11:32:16 +0700 Subject: [PATCH 1/2] feat(ui): add showFailedIndicator parameter into StreamMessageWidget --- packages/stream_chat_flutter/CHANGELOG.md | 4 ++++ .../lib/src/message_widget/message_widget.dart | 9 +++++++++ .../lib/src/message_widget/message_widget_content.dart | 6 +++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index 7f4861099..3cd194b80 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -33,6 +33,10 @@ ## 8.0.0 +✅ Added + +- Added `showFailedIndicator` parameter for `StreamMessageWidget` to toggle displaying the failed message icon. + 🐞 Fixed - Fixed null errors in web from markdown. diff --git a/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart b/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart index 153451c8d..963309e18 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart @@ -99,6 +99,7 @@ class StreamMessageWidget extends StatefulWidget { this.imageAttachmentThumbnailResizeType = 'clip', this.imageAttachmentThumbnailCropType = 'center', this.attachmentActionsModalBuilder, + this.showFailedIndicator = true, }); /// {@template onMentionTap} @@ -380,6 +381,11 @@ class StreamMessageWidget extends StatefulWidget { final String /*center|top|bottom|left|right*/ imageAttachmentThumbnailCropType; + /// {@template showFailedIndicator} + /// Show the failed message indicator + /// {@endtemplate} + final bool showFailedIndicator; + /// {@template copyWith} /// Creates a copy of [StreamMessageWidget] with specified attributes /// overridden. @@ -641,6 +647,8 @@ class _StreamMessageWidgetState extends State bool get shouldShowDeleteAction => widget.showDeleteMessage || isDeleteFailed; + bool get showFailedIndicator => widget.showFailedIndicator; + @override bool get wantKeepAlive => widget.message.attachments.isNotEmpty; @@ -762,6 +770,7 @@ class _StreamMessageWidgetState extends State widget.bottomRowBuilderWithDefaultWidget, onUserAvatarTap: widget.onUserAvatarTap, userAvatarBuilder: widget.userAvatarBuilder, + showFailedIndicator: showFailedIndicator, ); }), ), diff --git a/packages/stream_chat_flutter/lib/src/message_widget/message_widget_content.dart b/packages/stream_chat_flutter/lib/src/message_widget/message_widget_content.dart index 66c76fd6d..440e2d31b 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget/message_widget_content.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget/message_widget_content.dart @@ -64,6 +64,7 @@ class MessageWidgetContent extends StatelessWidget { required this.showEditedLabel, required this.messageWidget, required this.onThreadTap, + required this.showFailedIndicator, this.onUserAvatarTap, this.borderRadiusGeometry, this.borderSide, @@ -224,6 +225,9 @@ class MessageWidgetContent extends StatelessWidget { /// {@macro userAvatarBuilder} final Widget Function(BuildContext, User)? userAvatarBuilder; + /// {@macro showFailedIndicator} + final bool showFailedIndicator; + @override Widget build(BuildContext context) { return Column( @@ -418,7 +422,7 @@ class MessageWidgetContent extends StatelessWidget { ], ), ), - if (isFailedState) + if (isFailedState && showFailedIndicator) Positioned( right: reverse ? 0 : null, left: reverse ? null : 0, From 7e314f86db2dcfa8119c9a95505ff7ae0e33f974 Mon Sep 17 00:00:00 2001 From: TinhHuynh Date: Wed, 10 Jul 2024 15:48:05 +0700 Subject: [PATCH 2/2] added showFailedIndicator parameter to MessageCard --- .../lib/src/message_widget/message_card.dart | 9 +++++++-- .../lib/src/message_widget/message_widget.dart | 2 ++ .../lib/src/message_widget/message_widget_content.dart | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/message_widget/message_card.dart b/packages/stream_chat_flutter/lib/src/message_widget/message_card.dart index 0c981ad79..0fe2eeba2 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget/message_card.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget/message_card.dart @@ -28,6 +28,7 @@ class MessageCard extends StatefulWidget { required this.attachmentActionsModalBuilder, required this.textPadding, required this.reverse, + required this.showFailedIndicator, this.shape, this.borderSide, this.borderRadiusGeometry, @@ -116,6 +117,9 @@ class MessageCard extends StatefulWidget { /// {@macro reverse} final bool reverse; + /// {@macro showFailedIndicator} + final bool showFailedIndicator; + @override State createState() => _MessageCardState(); } @@ -161,8 +165,9 @@ class _MessageCardState extends State { return Container( constraints: const BoxConstraints().copyWith(maxWidth: widthLimit), margin: EdgeInsets.symmetric( - horizontal: (widget.isFailedState ? 15.0 : 0.0) + - (widget.showUserAvatar == DisplayWidget.gone ? 0 : 4.0), + horizontal: + (widget.isFailedState && widget.showFailedIndicator ? 15.0 : 0.0) + + (widget.showUserAvatar == DisplayWidget.gone ? 0 : 4.0), ), clipBehavior: Clip.hardEdge, decoration: ShapeDecoration( diff --git a/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart b/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart index 963309e18..bb3c03519 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart @@ -451,6 +451,7 @@ class StreamMessageWidget extends StatefulWidget { String? imageAttachmentThumbnailResizeType, String? imageAttachmentThumbnailCropType, AttachmentActionsBuilder? attachmentActionsModalBuilder, + bool? showFailedIndicator }) { return StreamMessageWidget( key: key ?? this.key, @@ -520,6 +521,7 @@ class StreamMessageWidget extends StatefulWidget { this.imageAttachmentThumbnailCropType, attachmentActionsModalBuilder: attachmentActionsModalBuilder ?? this.attachmentActionsModalBuilder, + showFailedIndicator: showFailedIndicator ?? this.showFailedIndicator, ); } diff --git a/packages/stream_chat_flutter/lib/src/message_widget/message_widget_content.dart b/packages/stream_chat_flutter/lib/src/message_widget/message_widget_content.dart index 440e2d31b..4148b1142 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget/message_widget_content.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget/message_widget_content.dart @@ -332,6 +332,8 @@ class MessageWidgetContent extends StatelessWidget { : MessageCard( message: message, isFailedState: isFailedState, + showFailedIndicator: + showFailedIndicator, showUserAvatar: showUserAvatar, messageTheme: messageTheme, hasQuotedMessage: hasQuotedMessage,