msgContentAttachmentsUI method

dynamic msgContentAttachmentsUI(
  1. dynamic context,
  2. dynamic ref
)

Implementation

Widget msgContentAttachmentsUI(BuildContext context, WidgetRef ref) {
  final lang = L10n.of(context);
  final msgContentAttachmentsLoader = ref.watch(
    msgContentAttachmentsProvider(attachmentManager),
  );
  bool canEdit = attachmentManager.canEditAttachments();

  return msgContentAttachmentsLoader.when(
    data: (msgContentAttachmentList) {
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          attachmentHeader(
            context: context,
            title: lang.attachments,
            canEdit: canEdit,
            onTapAdd:
                () => selectAttachment(
                  context: context,
                  onLinkSelected: (title, link) {
                    Navigator.pop(context);
                    return handleAttachmentSelected(
                      context: context,
                      ref: ref,
                      manager: attachmentManager,
                      title: title,
                      link: link,
                      attachmentType: AttachmentType.link,
                      attachments: [],
                    );
                  },
                  onSelected: (files, selectedType) {
                    return handleAttachmentSelected(
                      context: context,
                      ref: ref,
                      manager: attachmentManager,
                      attachments: files,
                      attachmentType: selectedType,
                    );
                  },
                ),
          ),
          ListView.builder(
            shrinkWrap: true,
            itemCount: msgContentAttachmentList.length,
            padding: EdgeInsets.zero,
            physics: NeverScrollableScrollPhysics(),
            itemBuilder: (context, index) {
              return MsgContentAttachmentItem(
                attachment: msgContentAttachmentList[index],
                canEdit: canEdit,
              );
            },
          ),
          if (msgContentAttachmentList.isEmpty)
            Text(L10n.of(context).attachmentEmptyStateTitle),
        ],
      );
    },
    error: (e, s) {
      _log.severe('Failed to load attachments', e, s);
      return Text(L10n.of(context).errorLoadingAttachments(e));
    },
    loading:
        () => const Skeletonizer(
          child: Wrap(spacing: 5.0, runSpacing: 10.0, children: []),
        ),
  );
}