Merge pull request #1608 from GetStream/feat/allowed-attachment-picker-types
This commit is contained in:
@@ -7,6 +7,21 @@
|
|||||||
- [[#1605]](https://github.com/GetStream/stream-chat-flutter/issues/1605) Fixed Null exception is thrown on message list
|
- [[#1605]](https://github.com/GetStream/stream-chat-flutter/issues/1605) Fixed Null exception is thrown on message list
|
||||||
for unread messages when `ScrollToBottomButton` is pressed.
|
for unread messages when `ScrollToBottomButton` is pressed.
|
||||||
|
|
||||||
|
✅ Added
|
||||||
|
|
||||||
|
- Added support for `StreamMessageInput.allowedAttachmentPickerTypes` to specify the allowed attachment picker types.
|
||||||
|
[#1601](https://github.com/GetStream/stream-chat-flutter/issues/1376)
|
||||||
|
|
||||||
|
```dart
|
||||||
|
StreamMessageInput(
|
||||||
|
...,
|
||||||
|
allowedAttachmentPickerTypes: const [
|
||||||
|
AttachmentPickerType.files,
|
||||||
|
AttachmentPickerType.images,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
## 6.3.0
|
## 6.3.0
|
||||||
|
|
||||||
🐞 Fixed
|
🐞 Fixed
|
||||||
|
|||||||
+6
@@ -693,6 +693,7 @@ Widget mobileAttachmentPickerBuilder({
|
|||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required StreamAttachmentPickerController controller,
|
required StreamAttachmentPickerController controller,
|
||||||
Iterable<AttachmentPickerOption>? customOptions,
|
Iterable<AttachmentPickerOption>? customOptions,
|
||||||
|
List<AttachmentPickerType> allowedTypes = AttachmentPickerType.values,
|
||||||
ThumbnailSize attachmentThumbnailSize = const ThumbnailSize(400, 400),
|
ThumbnailSize attachmentThumbnailSize = const ThumbnailSize(400, 400),
|
||||||
ThumbnailFormat attachmentThumbnailFormat = ThumbnailFormat.jpeg,
|
ThumbnailFormat attachmentThumbnailFormat = ThumbnailFormat.jpeg,
|
||||||
int attachmentThumbnailQuality = 100,
|
int attachmentThumbnailQuality = 100,
|
||||||
@@ -702,6 +703,7 @@ Widget mobileAttachmentPickerBuilder({
|
|||||||
controller: controller,
|
controller: controller,
|
||||||
onSendAttachments: Navigator.of(context).pop,
|
onSendAttachments: Navigator.of(context).pop,
|
||||||
options: {
|
options: {
|
||||||
|
...{
|
||||||
if (customOptions != null) ...customOptions,
|
if (customOptions != null) ...customOptions,
|
||||||
AttachmentPickerOption(
|
AttachmentPickerOption(
|
||||||
key: 'gallery-picker',
|
key: 'gallery-picker',
|
||||||
@@ -770,6 +772,7 @@ Widget mobileAttachmentPickerBuilder({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
}..where((option) => option.supportedTypes.every(allowedTypes.contains)),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -779,6 +782,7 @@ Widget webOrDesktopAttachmentPickerBuilder({
|
|||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required StreamAttachmentPickerController controller,
|
required StreamAttachmentPickerController controller,
|
||||||
Iterable<WebOrDesktopAttachmentPickerOption>? customOptions,
|
Iterable<WebOrDesktopAttachmentPickerOption>? customOptions,
|
||||||
|
List<AttachmentPickerType> allowedTypes = AttachmentPickerType.values,
|
||||||
ThumbnailSize attachmentThumbnailSize = const ThumbnailSize(400, 400),
|
ThumbnailSize attachmentThumbnailSize = const ThumbnailSize(400, 400),
|
||||||
ThumbnailFormat attachmentThumbnailFormat = ThumbnailFormat.jpeg,
|
ThumbnailFormat attachmentThumbnailFormat = ThumbnailFormat.jpeg,
|
||||||
int attachmentThumbnailQuality = 100,
|
int attachmentThumbnailQuality = 100,
|
||||||
@@ -787,6 +791,7 @@ Widget webOrDesktopAttachmentPickerBuilder({
|
|||||||
return StreamWebOrDesktopAttachmentPickerBottomSheet(
|
return StreamWebOrDesktopAttachmentPickerBottomSheet(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
options: {
|
options: {
|
||||||
|
...{
|
||||||
if (customOptions != null) ...customOptions,
|
if (customOptions != null) ...customOptions,
|
||||||
WebOrDesktopAttachmentPickerOption(
|
WebOrDesktopAttachmentPickerOption(
|
||||||
key: 'image-picker',
|
key: 'image-picker',
|
||||||
@@ -806,6 +811,7 @@ Widget webOrDesktopAttachmentPickerBuilder({
|
|||||||
icon: StreamSvgIcon.files(size: 36).toIconThemeSvgIcon(),
|
icon: StreamSvgIcon.files(size: 36).toIconThemeSvgIcon(),
|
||||||
title: context.translations.uploadAFileLabel,
|
title: context.translations.uploadAFileLabel,
|
||||||
),
|
),
|
||||||
|
}.where((option) => option.supportedTypes.every(allowedTypes.contains)),
|
||||||
},
|
},
|
||||||
onOptionTap: (context, controller, option) async {
|
onOptionTap: (context, controller, option) async {
|
||||||
final attachment = await StreamAttachmentHandler.instance.pickFile(
|
final attachment = await StreamAttachmentHandler.instance.pickFile(
|
||||||
|
|||||||
+3
@@ -66,6 +66,7 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
|||||||
Future<T?> showStreamAttachmentPickerModalBottomSheet<T>({
|
Future<T?> showStreamAttachmentPickerModalBottomSheet<T>({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
Iterable<AttachmentPickerOption>? customOptions,
|
Iterable<AttachmentPickerOption>? customOptions,
|
||||||
|
List<AttachmentPickerType> allowedTypes = AttachmentPickerType.values,
|
||||||
List<Attachment>? initialAttachments,
|
List<Attachment>? initialAttachments,
|
||||||
StreamAttachmentPickerController? controller,
|
StreamAttachmentPickerController? controller,
|
||||||
Color? backgroundColor,
|
Color? backgroundColor,
|
||||||
@@ -117,6 +118,7 @@ Future<T?> showStreamAttachmentPickerModalBottomSheet<T>({
|
|||||||
return webOrDesktopAttachmentPickerBuilder.call(
|
return webOrDesktopAttachmentPickerBuilder.call(
|
||||||
context: context,
|
context: context,
|
||||||
controller: controller,
|
controller: controller,
|
||||||
|
allowedTypes: allowedTypes,
|
||||||
customOptions: customOptions?.map(
|
customOptions: customOptions?.map(
|
||||||
WebOrDesktopAttachmentPickerOption.fromAttachmentPickerOption,
|
WebOrDesktopAttachmentPickerOption.fromAttachmentPickerOption,
|
||||||
),
|
),
|
||||||
@@ -130,6 +132,7 @@ Future<T?> showStreamAttachmentPickerModalBottomSheet<T>({
|
|||||||
return mobileAttachmentPickerBuilder.call(
|
return mobileAttachmentPickerBuilder.call(
|
||||||
context: context,
|
context: context,
|
||||||
controller: controller,
|
controller: controller,
|
||||||
|
allowedTypes: allowedTypes,
|
||||||
customOptions: customOptions,
|
customOptions: customOptions,
|
||||||
attachmentThumbnailSize: attachmentThumbnailSize,
|
attachmentThumbnailSize: attachmentThumbnailSize,
|
||||||
attachmentThumbnailFormat: attachmentThumbnailFormat,
|
attachmentThumbnailFormat: attachmentThumbnailFormat,
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ class StreamMessageInput extends StatefulWidget {
|
|||||||
this.maxAttachmentSize = kDefaultMaxAttachmentSize,
|
this.maxAttachmentSize = kDefaultMaxAttachmentSize,
|
||||||
this.onError,
|
this.onError,
|
||||||
this.attachmentLimit = 10,
|
this.attachmentLimit = 10,
|
||||||
|
this.allowedAttachmentPickerTypes = AttachmentPickerType.values,
|
||||||
this.onAttachmentLimitExceed,
|
this.onAttachmentLimitExceed,
|
||||||
this.attachmentButtonBuilder,
|
this.attachmentButtonBuilder,
|
||||||
this.commandButtonBuilder,
|
this.commandButtonBuilder,
|
||||||
@@ -233,6 +234,12 @@ class StreamMessageInput extends StatefulWidget {
|
|||||||
/// A limit for the no. of attachments that can be sent with a single message.
|
/// A limit for the no. of attachments that can be sent with a single message.
|
||||||
final int attachmentLimit;
|
final int attachmentLimit;
|
||||||
|
|
||||||
|
/// The list of allowed attachment types which can be picked using the
|
||||||
|
/// attachment button.
|
||||||
|
///
|
||||||
|
/// By default, all the attachment types are allowed.
|
||||||
|
final List<AttachmentPickerType> allowedAttachmentPickerTypes;
|
||||||
|
|
||||||
/// A callback for when the [attachmentLimit] is exceeded.
|
/// A callback for when the [attachmentLimit] is exceeded.
|
||||||
///
|
///
|
||||||
/// This will override the default error alert behaviour.
|
/// This will override the default error alert behaviour.
|
||||||
@@ -771,8 +778,9 @@ 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,
|
||||||
initialAttachments: _effectiveController.attachments,
|
|
||||||
useRootNavigator: true,
|
useRootNavigator: true,
|
||||||
|
allowedTypes: widget.allowedAttachmentPickerTypes,
|
||||||
|
initialAttachments: _effectiveController.attachments,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (attachments != null) {
|
if (attachments != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user