From dc3aa45383d8a4905d3618ea85612622c9a37098 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Tue, 11 Jun 2024 11:48:20 +0200 Subject: [PATCH] fix(ui): custom attachment builders (#1938) * added custom attachments to default builders * slight docs change * Update packages/stream_chat_flutter/CHANGELOG.md --- packages/stream_chat_flutter/CHANGELOG.md | 2 ++ .../builder/attachment_widget_builder.dart | 15 +++++++++------ .../lib/src/message_widget/parse_attachments.dart | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index e50cdb756..ec83cf318 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -2,6 +2,8 @@ ✅ Added +- Added `customAttachmentBuilders` parameter for `StreamAttachmentWidgetBuilder.defaultBuilders`. +- `attachmentBuilders` parameter for `StreamMessageWidget` now only expects custom builders. - Added `StreamMediaAttachmentBuilder` widget to show media attachments in a message. ## 7.2.1 diff --git a/packages/stream_chat_flutter/lib/src/attachment/builder/attachment_widget_builder.dart b/packages/stream_chat_flutter/lib/src/attachment/builder/attachment_widget_builder.dart index 5011e7daa..2314548bf 100644 --- a/packages/stream_chat_flutter/lib/src/attachment/builder/attachment_widget_builder.dart +++ b/packages/stream_chat_flutter/lib/src/attachment/builder/attachment_widget_builder.dart @@ -51,12 +51,12 @@ abstract class StreamAttachmentWidgetBuilder { /// Example: /// /// ```dart - /// final myBuilders = [ - /// ...StreamAttachmentWidgetBuilder.defaultBuilders, - /// MyCustomAttachmentBuilder(), - /// MyOtherCustomAttachmentBuilder(), - /// ... - /// ]; + /// final myBuilders = StreamAttachmentWidgetBuilder.defaultBuilders( + /// customAttachmentBuilders: [ + /// MyCustomAttachmentBuilder(), + /// MyOtherCustomAttachmentBuilder(), + /// ] + /// ); /// ``` /// /// **Note**: The order of the builders in the list is important. The first @@ -67,8 +67,11 @@ abstract class StreamAttachmentWidgetBuilder { ShapeBorder? shape, EdgeInsetsGeometry padding = const EdgeInsets.all(4), StreamAttachmentWidgetTapCallback? onAttachmentTap, + List? customAttachmentBuilders, }) { return [ + ...?customAttachmentBuilders, + // Handles a mix of image, gif, video, url and file attachments. MixedAttachmentBuilder( padding: padding, diff --git a/packages/stream_chat_flutter/lib/src/message_widget/parse_attachments.dart b/packages/stream_chat_flutter/lib/src/message_widget/parse_attachments.dart index c10f2cedb..0f460c367 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget/parse_attachments.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget/parse_attachments.dart @@ -104,12 +104,12 @@ class ParseAttachments extends StatelessWidget { }; // Create a default attachmentBuilders list if not provided. - var builders = attachmentBuilders; - builders ??= StreamAttachmentWidgetBuilder.defaultBuilders( + final builders = StreamAttachmentWidgetBuilder.defaultBuilders( message: message, shape: attachmentShape, padding: attachmentPadding, onAttachmentTap: onAttachmentTap, + customAttachmentBuilders: attachmentBuilders, ); final catalog = AttachmentWidgetCatalog(builders: builders);