stream-chat-flutter icon indicating copy to clipboard operation
stream-chat-flutter copied to clipboard

Lack of information on how use attachmentBuilders with custom attachment types

Open Mounix99 opened this issue 1 year ago • 8 comments

Which packages are you using?

stream_chat_flutter, stream_chat_persistance, stream_chat_localizations

On what platforms did you experience the issue?

iOS, Android, Web

What version are you using?

7.0.0

What happened?

customAttachmentBuilders was commented in the code and attachmentBuilders is unclear for custom attachment types. THe only info about it's usage I can find is this comment

/// final myBuilders = [
 ///  ...StreamAttachmentWidgetBuilder.defaultBuilders,
 ///  MyCustomAttachmentBuilder(),
 ///  MyOtherCustomAttachmentBuilder(),
 ///  ...
 /// ];

But StreamAttachmentWidgetBuilder.defaultBuilders couldn't be imported, so how should I deal with my custom attachments, can you provide a valid example ?

previously I was using it like this:

defaultMessage.copyWith(customAttachmentBuilders: {
      AttachmentTypes.voicenote.name: (_, __, attachments) => AudioMessage(attachments: attachments),
      AttachmentTypes.currentLocation.name: (_, message, attachments) =>
          LocationMessage(attachments: attachments, channelName: channelName ?? message.text ?? ''),
    });

Steps to reproduce

Try to add custom attachments builders to StreamMessageWidget

Supporting info to reproduce

No response

Relevant log output

No response

Flutter analyze output

No response

Flutter doctor output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

Mounix99 avatar Dec 06 '23 12:12 Mounix99

Any updates here ?

Mounix99 avatar Dec 13 '23 13:12 Mounix99

Few points I mentioned while trying to deal with this new implementation

  1. StreamAttachmentWidgetBuilder.defaultBuilders isn't accessible, why? How can I get the list of default builders ?According to the provided snippets it should be accessible.
  2. If I have custom types of attachments along with the provided by the package in same message I can't handle them both and I'm forced to override MixedAttachmentBuilder with my own implantation, same to the GalleryAttachmentBuilder.
  3. If I want to add my custom attachmentBuilders to already existing in the StreamMessageWidget I can't get existing from StreamMessageWidget instance provided by StreamMessageListView.messageBuilder as a list and expand it with mine, In case if I try call StreamAttachmentWidgetBuilder.defaultBuilders as I already said in point 1 it is not accessible. In case if I call type specific StreamAttachmentWidgetBuilders directly I will have no control over provided by package onAttachmentTap methods and I need to handle them by my own

Mounix99 avatar Dec 14 '23 11:12 Mounix99

@esarbanis Sorry for bothering you, but it is a big problem for our production along with the fact that without migrating to the stream_chat v7.x.x we blocked from updating the packages and migrating to last Flutter/Dart version. Can Some one at least mark it as an actual issue or provide me with any kind of solution ?

Mounix99 avatar Dec 14 '23 11:12 Mounix99

I am running into the same issue

khubaib-zeepalm avatar Dec 14 '23 13:12 khubaib-zeepalm

I think the logic was moved to the StreamAttachmentWidgetBuilder and there is a static method StreamAttachmentWidgetBuilder.defaultBuilders to return all the builders. HOWEVER, this class is not exposed (exported) and it's a private class in the package, thus you are pretty much lost when adding a custom attachment builder.

mkobuolys avatar Dec 19 '23 14:12 mkobuolys

@mkobuolys this class is already accessible but it has problem with StreamAttachmentWidgetBuilder.defaultBuilders which contains MixedAttachmentBuilder and GalleryAttachmentBuilder that this two builders are collections of widgets of attachments and they will ignore your custom attachment if you will have both custom and native in one message. Also problem that the last builder in that list is FallbackAttachmentBuilder() which will basically ignore your attachment builders if they are placed in the end. And few more that I have described higher

Mounix99 avatar Dec 20 '23 11:12 Mounix99

I'm having similar issue.

talkbiz avatar Jan 31 '24 21:01 talkbiz

https://github.com/GetStream/stream-chat-flutter/pull/1826

Mounix99 avatar Feb 20 '24 08:02 Mounix99

any updates here?

szechyjs avatar Jun 04 '24 03:06 szechyjs

Hey folks, apologies for the delays on this. I'm taking a look at this now.

deven98 avatar Jun 07 '24 08:06 deven98

Hey folks, an update here: we just merged #1938 with the help of @Mounix99 which simplifies this process by a lot:

To add custom attachments, you no longer have to provide any default attachment builders to the widget which will be added by default. I am also working on correcting the relevant documentation which should be done shortly.

To add custom attachments with the updates, you can now simply do:

    return messageWidget.copyWith(
        attachmentBuilders: [
          CustomAttachmentBuilder(),
          CustomAttachmentBuilder2(),
        ],
    );

You should be able to use the above code to add custom attachments on the master branch. The change will be rolled out in the next release but you can of course fetch the package from git if it is an immediate need.

I am closing this issue but feel free to open another if you have any relevant concerns here. Thanks!

deven98 avatar Jun 11 '24 09:06 deven98