build method

  1. @override
Widget build(
  1. BuildContext context,
  2. Message message,
  3. Map<String, List<Attachment>> attachments
)
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 files = attachments[AttachmentType.file]!;

  Widget _buildFileAttachment(Attachment file) {
    VoidCallback? onTap;
    if (onAttachmentTap != null) {
      onTap = () => onAttachmentTap!(message, file);
    }

    return InkWell(
      onTap: onTap,
      child: StreamFileAttachment(
        file: file,
        message: message,
        shape: shape,
        constraints: constraints,
        backgroundColor: backgroundColor,
      ),
    );
  }

  Widget child;
  if (files.length == 1) {
    child = _buildFileAttachment(files.first);
  } else {
    child = Column(
      children: <Widget>[
        for (final file in files) _buildFileAttachment(file),
      ].insertBetween(
        // Add a small vertical padding between each attachment.
        SizedBox(height: padding.vertical / 2),
      ),
    );
  }

  return Padding(
    padding: padding,
    child: child,
  );
}