diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index e50cdb756..9b71517ab 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -2,6 +2,7 @@ ✅ Added +- Added `customAttachmentBuilders` parameter for `StreamAttachmentWidgetBuilder.defaultBuilders`. - Added `StreamMediaAttachmentBuilder` widget to show media attachments in a message. ## 7.2.1 @@ -17,7 +18,6 @@ 🔄 Changed - Updated `stream_chat_flutter_core` dependency to [`7.2.0-hotfix.1`](https://pub.dev/packages/stream_chat/changelog). - ## 7.2.0 ✅ Added 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..2d3c74d57 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,23 +51,27 @@ 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 /// builder that returns `true` from [canHandle] will be used to build the /// widget. - static List defaultBuilders({ - required Message message, - ShapeBorder? shape, - EdgeInsetsGeometry padding = const EdgeInsets.all(4), - StreamAttachmentWidgetTapCallback? onAttachmentTap, - }) { + /// + /// **Note**: Builders provided with [customAttachmentBuilders] will not be + /// included into [MixedAttachmentBuilder] and [GalleryAttachmentBuilder], + /// use custom attachments in standalone messages. + static List defaultBuilders( + {required Message message, + ShapeBorder? shape, + EdgeInsetsGeometry padding = const EdgeInsets.all(4), + StreamAttachmentWidgetTapCallback? onAttachmentTap, + List? customAttachmentBuilders}) { return [ // Handles a mix of image, gif, video, url and file attachments. MixedAttachmentBuilder( @@ -122,6 +126,9 @@ abstract class StreamAttachmentWidgetBuilder { onAttachmentTap: onAttachmentTap, ), + // Handles attachment types provided by the user + ...?customAttachmentBuilders, + // Fallback builder should always be the last builder in the list. const FallbackAttachmentBuilder(), ]; 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..04504bf60 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,13 +104,12 @@ class ParseAttachments extends StatelessWidget { }; // Create a default attachmentBuilders list if not provided. - var builders = attachmentBuilders; - builders ??= StreamAttachmentWidgetBuilder.defaultBuilders( - message: message, - shape: attachmentShape, - padding: attachmentPadding, - onAttachmentTap: onAttachmentTap, - ); + final builders = StreamAttachmentWidgetBuilder.defaultBuilders( + message: message, + shape: attachmentShape, + padding: attachmentPadding, + onAttachmentTap: onAttachmentTap, + customAttachmentBuilders: attachmentBuilders); final catalog = AttachmentWidgetCatalog(builders: builders); return catalog.build(context, message);