feat: Added copyWith to stream_attachment_picker.dart

This commit is contained in:
Deven Joshi
2021-11-05 16:31:26 +05:30
parent e72cd81240
commit 9f32eb89f8
2 changed files with 61 additions and 9 deletions
@@ -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();
}