Merge branch 'message-input-controller' into feat/unfurl-url-client-side

This commit is contained in:
Salvatore Giordano
2021-12-28 11:37:28 +01:00
13 changed files with 137 additions and 70 deletions
@@ -23,41 +23,8 @@ typedef CustomAttachmentIconBuilder = Widget Function(
/// A widget that allows to pick an attachment.
class StreamAttachmentPicker extends StatefulWidget {
/// True if the picker is open.
final bool isOpen;
/// The picker size in height.
final double pickerSize;
/// The [MessageInputController] linked to this picker.
final MessageInputController messageInputController;
/// The limit of attachments that can be picked.
final int attachmentLimit;
/// The callback for when the attachment limit is exceeded.
final AttachmentLimitExceedListener? onAttachmentLimitExceeded;
final ValueChanged<String>? onError;
final FilePickerCallback onFilePicked;
/// Video quality to use when compressing the videos.
final VideoQuality compressedVideoQuality;
/// Frame rate to use when compressing the videos.
final int compressedVideoFrameRate;
/// Max attachment size in bytes:
/// - Defaults to 20 MB
/// - Do not set it if you're using our default CDN
final int maxAttachmentSize;
/// The list of attachment types that can be picked.
final List<DefaultAttachmentTypes> allowedAttachmentTypes;
/// The list of custom attachment types that can be picked.
final List<CustomAttachmentType> customAttachmentTypes;
/// Default constructor for [StreamAttachmentPicker] which creates the Stream
/// attachment picker widget.
const StreamAttachmentPicker({
Key? key,
required this.messageInputController,
@@ -78,6 +45,46 @@ class StreamAttachmentPicker extends StatefulWidget {
this.customAttachmentTypes = const [],
}) : super(key: key);
/// True if the picker is open.
final bool isOpen;
/// The picker size in height.
final double pickerSize;
/// The [MessageInputController] linked to this picker.
final MessageInputController messageInputController;
/// The limit of attachments that can be picked.
final int attachmentLimit;
/// The callback for when the attachment limit is exceeded.
final AttachmentLimitExceedListener? onAttachmentLimitExceeded;
/// Callback for when an error occurs in the attachment picker.
final ValueChanged<String>? onError;
/// Callback for when file is picked.
final FilePickerCallback onFilePicked;
/// Video quality to use when compressing the videos.
final VideoQuality compressedVideoQuality;
/// Frame rate to use when compressing the videos.
final int compressedVideoFrameRate;
/// Max attachment size in bytes:
/// - Defaults to 20 MB
/// - Do not set it if you're using our default CDN
final int maxAttachmentSize;
/// The list of attachment types that can be picked.
final List<DefaultAttachmentTypes> allowedAttachmentTypes;
/// The list of custom attachment types that can be picked.
final List<CustomAttachmentType> customAttachmentTypes;
/// Used to create a new copy of [StreamAttachmentPicker] with modified
/// properties.
StreamAttachmentPicker copyWith({
Key? key,
MessageInputController? messageInputController,
@@ -334,8 +341,8 @@ class _StreamAttachmentPickerState extends State<StreamAttachmentPicker> {
onMediaSelected: (media) {
if (messageInputController.attachments
.any((e) => e.id == media.id)) {
setState(() => messageInputController.attachments
.removeWhere((e) => e.id == media.id));
messageInputController
.removeAttachmentById(media.id);
} else {
_addAssetAttachment(media);
}
@@ -547,14 +554,22 @@ class _PickerWidgetState extends State<_PickerWidget> {
}
}
/// Class which holds data for a custom attachment type in the attachment picker
class CustomAttachmentType {
String type;
CustomAttachmentIconBuilder iconBuilder;
WidgetBuilder pickerBuilder;
/// Default constructor for creating a custom attachment for the attachment
/// picker.
CustomAttachmentType({
required this.type,
required this.iconBuilder,
required this.pickerBuilder,
});
/// Type name.
String type;
/// Builds the icon in the attachment picker top row.
CustomAttachmentIconBuilder iconBuilder;
/// Builds content in the attachment builder when icon is selected.
WidgetBuilder pickerBuilder;
}
@@ -1,4 +1,4 @@
// ignore_for_file: prefer-trailing-comma, cascade_invocations
// ignore_for_file: prefer-trailing-comma, cascade_invocations, lines_longer_than_80_chars
import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle;
@@ -44,7 +44,8 @@ class StreamMessageTextField extends StatefulWidget {
/// After [maxLength] characters have been input, additional input
/// is ignored, unless [maxLengthEnforcement] is set to
/// [MaxLengthEnforcement.none].
/// The text field enforces the length with a [LengthLimitingTextInputFormatter],
/// The text field enforces the length with a
/// [LengthLimitingTextInputFormatter],
/// which is evaluated after the supplied [inputFormatters], if any.
/// The [maxLength] value must be either null or greater than zero.
///
@@ -633,7 +634,7 @@ class StreamMessageTextField extends StatefulWidget {
defaultValue: null));
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>(
'scrollPadding', scrollPadding,
defaultValue: const EdgeInsets.all(20.0)));
defaultValue: const EdgeInsets.all(20)));
properties.add(FlagProperty('selectionEnabled',
value: selectionEnabled,
defaultValue: true,
@@ -702,7 +703,6 @@ class _StreamMessageTextFieldState extends State<StreamMessageTextField>
@override
Widget build(BuildContext context) => TextField(
key: widget.key,
controller: _effectiveController.textEditingController,
onChanged: (newText) {
_effectiveController.text = newText;