feat(ui): Add support for listening errors in AttachmentPicker.
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
+52
-17
@@ -698,6 +698,7 @@ Widget mobileAttachmentPickerBuilder({
|
|||||||
ThumbnailFormat attachmentThumbnailFormat = ThumbnailFormat.jpeg,
|
ThumbnailFormat attachmentThumbnailFormat = ThumbnailFormat.jpeg,
|
||||||
int attachmentThumbnailQuality = 100,
|
int attachmentThumbnailQuality = 100,
|
||||||
double attachmentThumbnailScale = 1,
|
double attachmentThumbnailScale = 1,
|
||||||
|
ErrorListener? onError,
|
||||||
}) {
|
}) {
|
||||||
return StreamMobileAttachmentPickerBottomSheet(
|
return StreamMobileAttachmentPickerBottomSheet(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
@@ -721,10 +722,15 @@ Widget mobileAttachmentPickerBuilder({
|
|||||||
mediaThumbnailQuality: attachmentThumbnailQuality,
|
mediaThumbnailQuality: attachmentThumbnailQuality,
|
||||||
mediaThumbnailScale: attachmentThumbnailScale,
|
mediaThumbnailScale: attachmentThumbnailScale,
|
||||||
onMediaItemSelected: (media) async {
|
onMediaItemSelected: (media) async {
|
||||||
if (selectedIds.contains(media.id)) {
|
try {
|
||||||
return controller.removeAssetAttachment(media);
|
if (selectedIds.contains(media.id)) {
|
||||||
|
return await controller.removeAssetAttachment(media);
|
||||||
|
}
|
||||||
|
return await controller.addAssetAttachment(media);
|
||||||
|
} catch (e, stk) {
|
||||||
|
if (onError != null) return onError.call(e, stk);
|
||||||
|
rethrow;
|
||||||
}
|
}
|
||||||
return controller.addAssetAttachment(media);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -736,8 +742,15 @@ Widget mobileAttachmentPickerBuilder({
|
|||||||
optionViewBuilder: (context, controller) {
|
optionViewBuilder: (context, controller) {
|
||||||
return StreamFilePicker(
|
return StreamFilePicker(
|
||||||
onFilePicked: (file) async {
|
onFilePicked: (file) async {
|
||||||
if (file != null) await controller.addAttachment(file);
|
try {
|
||||||
return Navigator.pop(context, controller.value);
|
if (file != null) await controller.addAttachment(file);
|
||||||
|
return Navigator.pop(context, controller.value);
|
||||||
|
} catch (e, stk) {
|
||||||
|
Navigator.pop(context, controller.value);
|
||||||
|
if (onError != null) return onError.call(e, stk);
|
||||||
|
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -749,10 +762,17 @@ Widget mobileAttachmentPickerBuilder({
|
|||||||
optionViewBuilder: (context, controller) {
|
optionViewBuilder: (context, controller) {
|
||||||
return StreamImagePicker(
|
return StreamImagePicker(
|
||||||
onImagePicked: (image) async {
|
onImagePicked: (image) async {
|
||||||
if (image != null) {
|
try {
|
||||||
await controller.addAttachment(image);
|
if (image != null) {
|
||||||
|
await controller.addAttachment(image);
|
||||||
|
}
|
||||||
|
return Navigator.pop(context, controller.value);
|
||||||
|
} catch (e, stk) {
|
||||||
|
Navigator.pop(context, controller.value);
|
||||||
|
if (onError != null) return onError.call(e, stk);
|
||||||
|
|
||||||
|
rethrow;
|
||||||
}
|
}
|
||||||
return Navigator.pop(context, controller.value);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -764,10 +784,17 @@ Widget mobileAttachmentPickerBuilder({
|
|||||||
optionViewBuilder: (context, controller) {
|
optionViewBuilder: (context, controller) {
|
||||||
return StreamVideoPicker(
|
return StreamVideoPicker(
|
||||||
onVideoPicked: (video) async {
|
onVideoPicked: (video) async {
|
||||||
if (video != null) {
|
try {
|
||||||
await controller.addAttachment(video);
|
if (video != null) {
|
||||||
|
await controller.addAttachment(video);
|
||||||
|
}
|
||||||
|
return Navigator.pop(context, controller.value);
|
||||||
|
} catch (e, stk) {
|
||||||
|
Navigator.pop(context, controller.value);
|
||||||
|
if (onError != null) return onError.call(e, stk);
|
||||||
|
|
||||||
|
rethrow;
|
||||||
}
|
}
|
||||||
return Navigator.pop(context, controller.value);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -787,6 +814,7 @@ Widget webOrDesktopAttachmentPickerBuilder({
|
|||||||
ThumbnailFormat attachmentThumbnailFormat = ThumbnailFormat.jpeg,
|
ThumbnailFormat attachmentThumbnailFormat = ThumbnailFormat.jpeg,
|
||||||
int attachmentThumbnailQuality = 100,
|
int attachmentThumbnailQuality = 100,
|
||||||
double attachmentThumbnailScale = 1,
|
double attachmentThumbnailScale = 1,
|
||||||
|
ErrorListener? onError,
|
||||||
}) {
|
}) {
|
||||||
return StreamWebOrDesktopAttachmentPickerBottomSheet(
|
return StreamWebOrDesktopAttachmentPickerBottomSheet(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
@@ -814,13 +842,20 @@ Widget webOrDesktopAttachmentPickerBuilder({
|
|||||||
}.where((option) => option.supportedTypes.every(allowedTypes.contains)),
|
}.where((option) => option.supportedTypes.every(allowedTypes.contains)),
|
||||||
},
|
},
|
||||||
onOptionTap: (context, controller, option) async {
|
onOptionTap: (context, controller, option) async {
|
||||||
final attachment = await StreamAttachmentHandler.instance.pickFile(
|
try {
|
||||||
type: option.type.fileType,
|
final attachment = await StreamAttachmentHandler.instance.pickFile(
|
||||||
);
|
type: option.type.fileType,
|
||||||
if (attachment != null) {
|
);
|
||||||
await controller.addAttachment(attachment);
|
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;
|
||||||
}
|
}
|
||||||
return Navigator.pop(context, controller.value);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -69,6 +69,7 @@ Future<T?> showStreamAttachmentPickerModalBottomSheet<T>({
|
|||||||
List<AttachmentPickerType> allowedTypes = AttachmentPickerType.values,
|
List<AttachmentPickerType> allowedTypes = AttachmentPickerType.values,
|
||||||
List<Attachment>? initialAttachments,
|
List<Attachment>? initialAttachments,
|
||||||
StreamAttachmentPickerController? controller,
|
StreamAttachmentPickerController? controller,
|
||||||
|
ErrorListener? onError,
|
||||||
Color? backgroundColor,
|
Color? backgroundColor,
|
||||||
double? elevation,
|
double? elevation,
|
||||||
BoxConstraints? constraints,
|
BoxConstraints? constraints,
|
||||||
@@ -117,6 +118,7 @@ Future<T?> showStreamAttachmentPickerModalBottomSheet<T>({
|
|||||||
if (isWebOrDesktop) {
|
if (isWebOrDesktop) {
|
||||||
return webOrDesktopAttachmentPickerBuilder.call(
|
return webOrDesktopAttachmentPickerBuilder.call(
|
||||||
context: context,
|
context: context,
|
||||||
|
onError: onError,
|
||||||
controller: controller,
|
controller: controller,
|
||||||
allowedTypes: allowedTypes,
|
allowedTypes: allowedTypes,
|
||||||
customOptions: customOptions?.map(
|
customOptions: customOptions?.map(
|
||||||
@@ -131,6 +133,7 @@ Future<T?> showStreamAttachmentPickerModalBottomSheet<T>({
|
|||||||
|
|
||||||
return mobileAttachmentPickerBuilder.call(
|
return mobileAttachmentPickerBuilder.call(
|
||||||
context: context,
|
context: context,
|
||||||
|
onError: onError,
|
||||||
controller: controller,
|
controller: controller,
|
||||||
allowedTypes: allowedTypes,
|
allowedTypes: allowedTypes,
|
||||||
customOptions: customOptions,
|
customOptions: customOptions,
|
||||||
|
|||||||
@@ -815,6 +815,7 @@ class StreamMessageInputState extends State<StreamMessageInput>
|
|||||||
Future<void> _onAttachmentButtonPressed() async {
|
Future<void> _onAttachmentButtonPressed() async {
|
||||||
final attachments = await showStreamAttachmentPickerModalBottomSheet(
|
final attachments = await showStreamAttachmentPickerModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
|
onError: widget.onError,
|
||||||
allowedTypes: widget.allowedAttachmentPickerTypes,
|
allowedTypes: widget.allowedAttachmentPickerTypes,
|
||||||
initialAttachments: _effectiveController.attachments,
|
initialAttachments: _effectiveController.attachments,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user