stream-chat-flutter
stream-chat-flutter copied to clipboard
Lack of information on how use attachmentBuilders with custom attachment types
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
Any updates here ?
Few points I mentioned while trying to deal with this new implementation
StreamAttachmentWidgetBuilder.defaultBuildersisn't accessible, why? How can I get the list of default builders ?According to the provided snippets it should be accessible.- 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
MixedAttachmentBuilderwith my own implantation, same to theGalleryAttachmentBuilder. - If I want to add my custom
attachmentBuildersto already existing in theStreamMessageWidgetI can't get existing fromStreamMessageWidgetinstance provided byStreamMessageListView.messageBuilderas a list and expand it with mine, In case if I try callStreamAttachmentWidgetBuilder.defaultBuildersas I already said inpoint 1it is not accessible. In case if I call type specificStreamAttachmentWidgetBuilders directly I will have no control over provided by packageonAttachmentTapmethods and I need to handle them by my own
@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 ?
I am running into the same issue
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 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
I'm having similar issue.
https://github.com/GetStream/stream-chat-flutter/pull/1826
any updates here?
Hey folks, apologies for the delays on this. I'm taking a look at this now.
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!