build method

  1. @override
dynamic build(
  1. dynamic context,
  2. dynamic ref
)

Implementation

@override
Widget build(BuildContext context, WidgetRef ref) {
  final containerColor = Theme.of(context).colorScheme.surface;
  final attachmentType = AttachmentType.values.byName(attachment.typeStr());
  final eventId = attachment.attachmentIdStr();
  final roomId = attachment.roomIdStr();
  final mediaState = ref.watch(attachmentMediaStateProvider(attachment));

  return Container(
    decoration: BoxDecoration(
      color: containerColor,
      borderRadius: BorderRadius.circular(8),
      border: Border.all(color: Theme.of(context).unselectedWidgetColor),
    ),
    child: ListTile(
      leading: attachmentLeadingIcon(attachmentType),
      onTap: () => attachmentOnTap(
        ref,
        context,
        attachmentType,
        mediaState,
      ),
      title: title(context, attachmentType),
      trailing: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          if (mediaState.mediaFile == null &&
              attachmentType != AttachmentType.link)
            mediaState.mediaLoadingState.isLoading || mediaState.isDownloading
                ? loadingIndication()
                : IconButton(
                    onPressed: () => ref
                        .read(
                          attachmentMediaStateProvider(attachment).notifier,
                        )
                        .downloadMedia(),
                    icon: Icon(
                      Icons.download,
                      color: Theme.of(context).primaryColor,
                    ),
                  ),
          if (canEdit)
            PopupMenuButton<String>(
              key: const Key('attachment-item-menu-options'),
              icon: const Icon(Icons.more_vert),
              itemBuilder: (context) => [
                PopupMenuItem<String>(
                  key: const Key('attachment-delete'),
                  onTap: () {
                    openRedactContentDialog(
                      context,
                      eventId: eventId,
                      roomId: roomId,
                      title: L10n.of(context).deleteAttachment,
                      description: L10n.of(context)
                          .areYouSureYouWantToRemoveAttachmentFromPin,
                      isSpace: true,
                    );
                  },
                  child: Text(
                    L10n.of(context).delete,
                    style: TextStyle(
                      color: Theme.of(context).colorScheme.error,
                    ),
                  ),
                ),
              ],
            ),
        ],
      ),
    ),
  );
}