webOrDesktopAttachmentPickerBuilder function
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}
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;
}
},
);
}