webOrDesktopAttachmentPickerBuilder function

Widget webOrDesktopAttachmentPickerBuilder(
  1. {required BuildContext context,
  2. required StreamAttachmentPickerController controller,
  3. Iterable<WebOrDesktopAttachmentPickerOption>? customOptions,
  4. List<AttachmentPickerType> allowedTypes = AttachmentPickerType.values,
  5. ThumbnailSize attachmentThumbnailSize = const ThumbnailSize(400, 400),
  6. ThumbnailFormat attachmentThumbnailFormat = ThumbnailFormat.jpeg,
  7. int attachmentThumbnailQuality = 100,
  8. double attachmentThumbnailScale = 1,
  9. ErrorListener? onError}
)

Returns the web or desktop version of the attachment picker.

Implementation

Widget webOrDesktopAttachmentPickerBuilder({
  required BuildContext context,
  required StreamAttachmentPickerController controller,
  Iterable<WebOrDesktopAttachmentPickerOption>? customOptions,
  List<AttachmentPickerType> allowedTypes = AttachmentPickerType.values,
  ThumbnailSize attachmentThumbnailSize = const ThumbnailSize(400, 400),
  ThumbnailFormat attachmentThumbnailFormat = ThumbnailFormat.jpeg,
  int attachmentThumbnailQuality = 100,
  double attachmentThumbnailScale = 1,
  ErrorListener? onError,
}) {
  return StreamWebOrDesktopAttachmentPickerBottomSheet(
    controller: controller,
    options: {
      ...{
        if (customOptions != null) ...customOptions,
        WebOrDesktopAttachmentPickerOption(
          key: 'image-picker',
          type: AttachmentPickerType.images,
          icon: StreamSvgIcon.pictures(size: 36).toIconThemeSvgIcon(),
          title: context.translations.uploadAPhotoLabel,
        ),
        WebOrDesktopAttachmentPickerOption(
          key: 'video-picker',
          type: AttachmentPickerType.videos,
          icon: StreamSvgIcon.record(size: 36).toIconThemeSvgIcon(),
          title: context.translations.uploadAVideoLabel,
        ),
        WebOrDesktopAttachmentPickerOption(
          key: 'file-picker',
          type: AttachmentPickerType.files,
          icon: StreamSvgIcon.files(size: 36).toIconThemeSvgIcon(),
          title: context.translations.uploadAFileLabel,
        ),
      }.where((option) => option.supportedTypes.every(allowedTypes.contains)),
    },
    onOptionTap: (context, controller, option) async {
      try {
        final attachment = await StreamAttachmentHandler.instance.pickFile(
          type: option.type.fileType,
        );
        if (attachment != null) {
          await controller.addAttachment(attachment);
        }
        return Navigator.pop(context, controller.value);
      } catch (e, stk) {
        Navigator.pop(context, controller.value);
        if (onError != null) return onError.call(e, stk);

        rethrow;
      }
    },
  );
}