build method
Widget
build(
- BuildContext context,
- Message message,
- Map<
String, List< attachmentsAttachment> >
override
Builds a widget for the given message
and attachments
.
This will only be called if canHandle returns true
.
Implementation
@override
Widget build(
BuildContext context,
Message message,
Map<String, List<Attachment>> attachments,
) {
assert(debugAssertCanHandle(message, attachments), '');
final urls = attachments[AttachmentType.urlPreview];
final files = attachments[AttachmentType.file];
final images = attachments[AttachmentType.image];
final videos = attachments[AttachmentType.video];
final giphys = attachments[AttachmentType.giphy];
final shouldBuildGallery = [...?images, ...?videos, ...?giphys].length > 1;
return Padding(
padding: padding,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (urls != null)
_urlAttachmentBuilder.build(context, message, {
AttachmentType.urlPreview: urls,
}),
if (files != null)
_fileAttachmentBuilder.build(context, message, {
AttachmentType.file: files,
}),
if (shouldBuildGallery)
_galleryAttachmentBuilder.build(context, message, {
if (images != null) AttachmentType.image: images,
if (videos != null) AttachmentType.video: videos,
if (giphys != null) AttachmentType.giphy: giphys,
})
else if (images != null && images.length == 1)
_imageAttachmentBuilder.build(context, message, {
AttachmentType.image: images,
})
else if (videos != null && videos.length == 1)
_videoAttachmentBuilder.build(context, message, {
AttachmentType.video: videos,
})
else if (giphys != null && giphys.length == 1)
_giphyAttachmentBuilder.build(context, message, {
AttachmentType.giphy: giphys,
}),
].insertBetween(
SizedBox(height: padding.vertical / 2),
),
),
);
}