From ecf0f42d6c2b750d1b3089f392b25de0f7b8220a Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 20 May 2021 15:52:03 +0200 Subject: [PATCH] add MessageInput.maxAttachmentSize prop --- .../lib/src/message_input.dart | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/message_input.dart b/packages/stream_chat_flutter/lib/src/message_input.dart index c71fd341..6d3ec5cf 100644 --- a/packages/stream_chat_flutter/lib/src/message_input.dart +++ b/packages/stream_chat_flutter/lib/src/message_input.dart @@ -76,7 +76,7 @@ enum SendButtonLocation { const _kMinMediaPickerSize = 360.0; -const _kMaxAttachmentSize = 20971520; // 20MB in Bytes +const _kDefaultMaxAttachmentSize = 20971520; // 20MB in Bytes /// Inactive state /// ![screenshot](https://raw.githubusercontent.com/GetStream/stream-chat-flutter/master/screenshots/message_input.png) @@ -148,11 +148,16 @@ class MessageInput extends StatefulWidget { this.activeSendButton, this.showCommandsButton = true, this.mentionsTileBuilder, + this.maxAttachmentSize = _kDefaultMaxAttachmentSize, }) : super(key: key); /// Message to edit final Message? editMessage; + /// Max attachment size in bytes + /// If you're using our default CDN do not set it + final int maxAttachmentSize; + /// Message to start with final Message? initialMessage; @@ -1108,12 +1113,12 @@ class MessageInputState extends State { bytes: mediaFile.readAsBytesSync(), ); - if (file.size! > _kMaxAttachmentSize) { + if (file.size! > widget.maxAttachmentSize) { if (medium.type == AssetType.video) { final mediaInfo = await (VideoService.compressVideo(file.path) as FutureOr); - if (mediaInfo.filesize! > _kMaxAttachmentSize) { + if (mediaInfo.filesize! > widget.maxAttachmentSize) { _showErrorAlert( // ignore: lines_longer_than_80_chars 'The file is too large to upload. The file size limit is 20MB. We tried compressing it, but it was not enough.', @@ -1896,12 +1901,12 @@ class MessageInputState extends State { extraData: extraDataMap, ); - if (file.size! > _kMaxAttachmentSize) { + if (file.size! > widget.maxAttachmentSize) { if (attachmentType == 'Video') { final mediaInfo = await (VideoService.compressVideo(file.path) as FutureOr); - if (mediaInfo.filesize! > _kMaxAttachmentSize) { + if (mediaInfo.filesize! > widget.maxAttachmentSize) { _showErrorAlert( // ignore: lines_longer_than_80_chars 'The file is too large to upload. The file size limit is 20MB. We tried compressing it, but it was not enough.',