diff --git a/packages/stream_chat_flutter/lib/src/message_input.dart b/packages/stream_chat_flutter/lib/src/message_input.dart index 6ee5c435..61ac3ac6 100644 --- a/packages/stream_chat_flutter/lib/src/message_input.dart +++ b/packages/stream_chat_flutter/lib/src/message_input.dart @@ -84,6 +84,13 @@ typedef MessageRelatedBuilder = Widget Function( MessageInputController messageInputController, ); +/// Widget builder for a custom attachment picker. +typedef AttachmentsPickerBuilder = Widget Function( + BuildContext context, + MessageInputController messageInputController, + StreamAttachmentPicker defaultPicker, +); + /// Location for actions on the [MessageInput] enum ActionsLocation { /// Align to left @@ -330,7 +337,7 @@ class MessageInput extends StatefulWidget { final bool mentionAllAppUsers; /// Builds bottom sheet when attachment picker is opened. - final MessageRelatedBuilder? attachmentsPickerBuilder; + final AttachmentsPickerBuilder? attachmentsPickerBuilder; /// Builder for creating send button final MessageRelatedBuilder? sendButtonBuilder; @@ -951,14 +958,7 @@ class MessageInputState extends State { } Widget _buildFilePickerSection() { - if (_openFilePickerSection && widget.attachmentsPickerBuilder != null) { - return widget.attachmentsPickerBuilder!( - context, - messageInputController, - ); - } - - return StreamAttachmentPicker( + final picker = StreamAttachmentPicker( messageInputController: messageInputController, onFilePicked: pickFile, isOpen: _openFilePickerSection, @@ -975,6 +975,16 @@ class MessageInputState extends State { }, onError: _showErrorAlert, ); + + if (_openFilePickerSection && widget.attachmentsPickerBuilder != null) { + return widget.attachmentsPickerBuilder!( + context, + messageInputController, + picker, + ); + } + + return picker; } Widget _buildMentionsOverlayEntry() { diff --git a/packages/stream_chat_flutter/lib/src/mip/stream_attachment_picker.dart b/packages/stream_chat_flutter/lib/src/mip/stream_attachment_picker.dart index ea7d54fb..f075a09c 100644 --- a/packages/stream_chat_flutter/lib/src/mip/stream_attachment_picker.dart +++ b/packages/stream_chat_flutter/lib/src/mip/stream_attachment_picker.dart @@ -9,16 +9,19 @@ import 'package:stream_chat_flutter/src/video_service.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'package:video_compress/video_compress.dart'; +/// Callback for when a file has to be picked. typedef FilePickerCallback = void Function( DefaultAttachmentTypes fileType, { bool camera, }); +/// Callback for building an icon for a custom attachment type. typedef CustomAttachmentIconBuilder = Widget Function( BuildContext context, bool active, ); +/// class StreamAttachmentPicker extends StatefulWidget { final bool isOpen; final double pickerSize; @@ -65,6 +68,45 @@ class StreamAttachmentPicker extends StatefulWidget { this.customAttachmentTypes = const [], }) : super(key: key); + StreamAttachmentPicker copyWith({ + Key? key, + MessageInputController? messageInputController, + FilePickerCallback? onFilePicked, + bool? isOpen, + double? pickerSize, + int? attachmentLimit, + AttachmentLimitExceedListener? onAttachmentLimitExceeded, + int? maxAttachmentSize, + VideoQuality? compressedVideoQuality, + int? compressedVideoFrameRate, + ValueChanged? onChangeInputState, + ValueChanged? onError, + List? allowedAttachmentTypes, + List? customAttachmentTypes = const [], + }) => + StreamAttachmentPicker( + key: key ?? this.key, + messageInputController: + messageInputController ?? this.messageInputController, + onFilePicked: onFilePicked ?? this.onFilePicked, + isOpen: isOpen ?? this.isOpen, + pickerSize: pickerSize ?? this.pickerSize, + attachmentLimit: attachmentLimit ?? this.attachmentLimit, + onAttachmentLimitExceeded: + onAttachmentLimitExceeded ?? this.onAttachmentLimitExceeded, + maxAttachmentSize: maxAttachmentSize ?? this.maxAttachmentSize, + compressedVideoQuality: + compressedVideoQuality ?? this.compressedVideoQuality, + compressedVideoFrameRate: + compressedVideoFrameRate ?? this.compressedVideoFrameRate, + onChangeInputState: onChangeInputState ?? this.onChangeInputState, + onError: onError ?? this.onError, + allowedAttachmentTypes: + allowedAttachmentTypes ?? this.allowedAttachmentTypes, + customAttachmentTypes: + customAttachmentTypes ?? this.customAttachmentTypes, + ); + @override State createState() => _StreamAttachmentPickerState(); }