fix(ui): disable camera and video button if attachment limit is crossed.

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2021-08-23 16:49:03 +05:30
committed by xsahil03x
parent d67ff91e12
commit 0bdfff5bf6
@@ -1042,6 +1042,9 @@ class MessageInputState extends State<MessageInput> {
final _attachmentContainsFile = final _attachmentContainsFile =
_attachments.values.any((it) => it.type == 'file'); _attachments.values.any((it) => it.type == 'file');
final attachmentLimitCrossed =
_attachments.length >= widget.attachmentLimit;
Color _getIconColor(int index) { Color _getIconColor(int index) {
final streamChatThemeData = _streamChatTheme; final streamChatThemeData = _streamChatTheme;
switch (index) { switch (index) {
@@ -1061,15 +1064,21 @@ class MessageInputState extends State<MessageInput> {
: streamChatThemeData.colorTheme.textHighEmphasis : streamChatThemeData.colorTheme.textHighEmphasis
.withOpacity(0.2)); .withOpacity(0.2));
case 2: case 2:
return _attachmentContainsFile && _attachments.isNotEmpty return attachmentLimitCrossed
? streamChatThemeData.colorTheme.textHighEmphasis.withOpacity(0.2) ? streamChatThemeData.colorTheme.textHighEmphasis.withOpacity(0.2)
: streamChatThemeData.colorTheme.textHighEmphasis : _attachmentContainsFile && _attachments.isNotEmpty
.withOpacity(0.5); ? streamChatThemeData.colorTheme.textHighEmphasis
.withOpacity(0.2)
: streamChatThemeData.colorTheme.textHighEmphasis
.withOpacity(0.5);
case 3: case 3:
return _attachmentContainsFile && _attachments.isNotEmpty return attachmentLimitCrossed
? streamChatThemeData.colorTheme.textHighEmphasis.withOpacity(0.2) ? streamChatThemeData.colorTheme.textHighEmphasis.withOpacity(0.2)
: streamChatThemeData.colorTheme.textHighEmphasis : _attachmentContainsFile && _attachments.isNotEmpty
.withOpacity(0.5); ? streamChatThemeData.colorTheme.textHighEmphasis
.withOpacity(0.2)
: streamChatThemeData.colorTheme.textHighEmphasis
.withOpacity(0.5);
default: default:
return Colors.black; return Colors.black;
} }
@@ -1112,7 +1121,8 @@ class MessageInputState extends State<MessageInput> {
icon: StreamSvgIcon.camera( icon: StreamSvgIcon.camera(
color: _getIconColor(2), color: _getIconColor(2),
), ),
onPressed: _attachmentContainsFile && _attachments.isNotEmpty onPressed: attachmentLimitCrossed ||
(_attachmentContainsFile && _attachments.isNotEmpty)
? null ? null
: () { : () {
pickFile(DefaultAttachmentTypes.image, camera: true); pickFile(DefaultAttachmentTypes.image, camera: true);
@@ -1123,7 +1133,8 @@ class MessageInputState extends State<MessageInput> {
icon: StreamSvgIcon.record( icon: StreamSvgIcon.record(
color: _getIconColor(3), color: _getIconColor(3),
), ),
onPressed: _attachmentContainsFile && _attachments.isNotEmpty onPressed: attachmentLimitCrossed ||
(_attachmentContainsFile && _attachments.isNotEmpty)
? null ? null
: () { : () {
pickFile(DefaultAttachmentTypes.video, camera: true); pickFile(DefaultAttachmentTypes.video, camera: true);