feat: Added copyWith to stream_attachment_picker.dart
This commit is contained in:
@@ -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<MessageInput> {
|
||||
}
|
||||
|
||||
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<MessageInput> {
|
||||
},
|
||||
onError: _showErrorAlert,
|
||||
);
|
||||
|
||||
if (_openFilePickerSection && widget.attachmentsPickerBuilder != null) {
|
||||
return widget.attachmentsPickerBuilder!(
|
||||
context,
|
||||
messageInputController,
|
||||
picker,
|
||||
);
|
||||
}
|
||||
|
||||
return picker;
|
||||
}
|
||||
|
||||
Widget _buildMentionsOverlayEntry() {
|
||||
|
||||
@@ -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<bool>? onChangeInputState,
|
||||
ValueChanged<String>? onError,
|
||||
List<DefaultAttachmentTypes>? allowedAttachmentTypes,
|
||||
List<CustomAttachmentType>? 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<StreamAttachmentPicker> createState() => _StreamAttachmentPickerState();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user