From f7c3721a8dfbdc7d84eb808b3ca790dde551f563 Mon Sep 17 00:00:00 2001 From: Nikita Mikhaulov Date: Fri, 22 Dec 2023 16:27:19 +0100 Subject: [PATCH 1/2] rework_custom_attachments_builders --- .../builder/attachment_widget_builder.dart | 31 ++++++++++++------- .../src/message_widget/parse_attachments.dart | 13 ++++---- 2 files changed, 25 insertions(+), 19 deletions(-) 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 f9b389ef2..7f8ffa240 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 @@ -60,23 +60,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( @@ -128,6 +132,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); From 26f16934dc05e911beb5efb5ffe0510da5444850 Mon Sep 17 00:00:00 2001 From: Nikita Mikhaulov Date: Fri, 22 Dec 2023 16:42:12 +0100 Subject: [PATCH 2/2] changelog --- packages/stream_chat_flutter/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index aeeb6b74e..779fef81c 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -1,3 +1,10 @@ +## Upcoming + +✅ Added + +- Added `customAttachmentBuilders` parameter for `StreamAttachmentWidgetBuilder.defaultBuilders`. + This will allow more easily provide custom attachment builders and will fix problem with providing `onAttachmentTap` method + ## 7.0.1 🐞 Fixed