Skip to content

Commit 8866592

Browse files
authored
feat(ui): add error badge for failed and bounced messages (#2597)
Co-authored-by: xsahil03x <25670178+xsahil03x@users.noreply.github.com>
1 parent 36a72bf commit 8866592

14 files changed

Lines changed: 42 additions & 12 deletions

melos.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ command:
9595
stream_core_flutter:
9696
git:
9797
url: https://github.com/GetStream/stream-core-flutter.git
98-
ref: 4b976d340f7ce085c4b41b7322f82555758ce893
98+
ref: c0c5986c2388d7064b81e207ad82ddadb9021032
9999
path: packages/stream_core_flutter
100100
synchronized: ^3.1.0+1
101101
thumblr: ^0.0.4

packages/stream_chat_flutter/lib/src/message_modal/message_modal.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class StreamMessageDialog extends StatelessWidget {
2727
this.useSafeArea = true,
2828
this.insetAnimationDuration = const Duration(milliseconds: 100),
2929
this.insetAnimationCurve = Curves.decelerate,
30-
this.insetPadding = const EdgeInsets.all(8),
30+
this.insetPadding = const EdgeInsets.all(16),
3131
this.alignment = Alignment.center,
3232
});
3333

packages/stream_chat_flutter/lib/src/message_widget/components/stream_message_content.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class StreamMessageContent extends StatefulWidget {
3434
super.key,
3535
required this.message,
3636
this.annotation,
37+
this.errorBadge,
3738
this.metadata,
3839
this.replies,
3940
this.attachmentBuilders,
@@ -56,6 +57,12 @@ class StreamMessageContent extends StatefulWidget {
5657
/// or show-in-channel annotations.
5758
final Widget? annotation;
5859

60+
/// Optional error badge widget overlaid on the message bubble.
61+
///
62+
/// When non-null, the badge is positioned at the top-end corner of the
63+
/// bubble using a [Stack] with [PositionedDirectional].
64+
final Widget? errorBadge;
65+
5966
/// Optional metadata widget displayed below the message content column.
6067
///
6168
/// Typically a [StreamMessageMetadata] containing the author name, timestamp,
@@ -208,7 +215,19 @@ class _StreamMessageContentState extends State<StreamMessageContent> {
208215
),
209216
);
210217

211-
return core.StreamMessageBubble(child: bubbleContent);
218+
final bubble = core.StreamMessageBubble(child: bubbleContent);
219+
220+
if (widget.errorBadge case final errorBadge?) {
221+
return Stack(
222+
clipBehavior: .none,
223+
children: [
224+
bubble,
225+
PositionedDirectional(top: 8, end: -12, child: errorBadge),
226+
],
227+
);
228+
}
229+
230+
return bubble;
212231
},
213232
),
214233
),

packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ class DefaultStreamMessage extends StatelessWidget {
443443
context,
444444
isPinned: message.pinned,
445445
isEdited: message.messageTextUpdatedAt != null,
446+
isBouncedWithError: message.isBouncedWithError,
446447
state: message.state,
447448
);
448449

@@ -453,6 +454,7 @@ class DefaultStreamMessage extends StatelessWidget {
453454
final effectiveBackgroundColor = props.backgroundColor ?? theme.backgroundColor ?? defaults.backgroundColor;
454455
final effectiveAvatarVisibility = resolve((theme) => theme?.avatarVisibility);
455456
final effectiveAnnotationVisibility = resolve((theme) => theme?.annotationVisibility);
457+
final effectiveErrorBadgeVisibility = resolve((theme) => theme?.errorBadgeVisibility);
456458
final effectiveMetadataVisibility = resolve((theme) => theme?.metadataVisibility);
457459
final effectiveRepliesVisibility = resolve((theme) => theme?.repliesVisibility);
458460

@@ -468,16 +470,13 @@ class DefaultStreamMessage extends StatelessWidget {
468470
);
469471
}
470472

471-
final listKind = StreamMessageLayout.listKindOf(context);
472-
final onViewTap = switch ((listKind, props.onViewInChannelTap)) {
473-
(.thread, final onTap?) => () => onTap(message),
474-
_ => () => _onViewThread(context, message),
475-
};
476-
477473
final annotationWidget = effectiveAnnotationVisibility.apply(
478474
StreamMessageAnnotations(
479475
message: message,
480-
onViewChannelTap: onViewTap,
476+
onViewChannelTap: switch (props.onViewInChannelTap) {
477+
final onTap? => () => onTap(message),
478+
_ => () => _onViewThread(context, message),
479+
},
481480
),
482481
);
483482

@@ -500,9 +499,14 @@ class DefaultStreamMessage extends StatelessWidget {
500499
);
501500
}
502501

502+
final errorBadgeWidget = effectiveErrorBadgeVisibility.apply(
503+
core.StreamErrorBadge(size: core.StreamErrorBadgeSize.sm),
504+
);
505+
503506
final contentWidget = StreamMessageContent(
504507
message: message,
505508
annotation: annotationWidget,
509+
errorBadge: errorBadgeWidget,
506510
metadata: metadataWidget,
507511
replies: repliesWidget,
508512
attachmentBuilders: props.attachmentBuilders,
@@ -1045,11 +1049,13 @@ class _StreamMessageWidgetDefaults extends core.StreamMessageItemThemeData {
10451049
this._context, {
10461050
this.isPinned = false,
10471051
this.isEdited = false,
1052+
this.isBouncedWithError = false,
10481053
required MessageState state,
10491054
}) : _messageState = state;
10501055

10511056
final bool isPinned;
10521057
final bool isEdited;
1058+
final bool isBouncedWithError;
10531059

10541060
final BuildContext _context;
10551061
final MessageState _messageState;
@@ -1084,6 +1090,11 @@ class _StreamMessageWidgetDefaults extends core.StreamMessageItemThemeData {
10841090
@override
10851091
core.StreamMessageLayoutVisibility get annotationVisibility => .all(.visible);
10861092

1093+
@override
1094+
core.StreamMessageLayoutVisibility get errorBadgeVisibility => .all(
1095+
_messageState.isFailed || isBouncedWithError ? .visible : .gone,
1096+
);
1097+
10871098
@override
10881099
core.StreamMessageLayoutVisibility get metadataVisibility {
10891100
if (isEdited) return .all(.visible);

packages/stream_chat_flutter/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ dependencies:
6262
stream_core_flutter:
6363
git:
6464
url: https://github.com/GetStream/stream-core-flutter.git
65-
ref: 4b976d340f7ce085c4b41b7322f82555758ce893
65+
ref: c0c5986c2388d7064b81e207ad82ddadb9021032
6666
path: packages/stream_core_flutter
6767
svg_icon_widget: ^0.0.1
6868
synchronized: ^3.1.0+1
7 Bytes
Loading
21 Bytes
Loading
11 Bytes
Loading
24 Bytes
Loading
28 Bytes
Loading

0 commit comments

Comments
 (0)