feat: Icons are now disabled according to file type chosen
This commit is contained in:
committed by
Salvatore Giordano
parent
e1c1e053b3
commit
c4c0f97f34
+70
-52
@@ -108,7 +108,6 @@ class MessageInput extends StatefulWidget {
|
|||||||
this.actionsLocation = ActionsLocation.left,
|
this.actionsLocation = ActionsLocation.left,
|
||||||
this.attachmentThumbnailBuilders,
|
this.attachmentThumbnailBuilders,
|
||||||
this.focusNode,
|
this.focusNode,
|
||||||
this.enableFileAndImageAttachment = false,
|
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Message to edit
|
/// Message to edit
|
||||||
@@ -157,9 +156,6 @@ class MessageInput extends StatefulWidget {
|
|||||||
/// The focus node associated to the TextField
|
/// The focus node associated to the TextField
|
||||||
final FocusNode focusNode;
|
final FocusNode focusNode;
|
||||||
|
|
||||||
/// Enables adding both file+images at the same time
|
|
||||||
final bool enableFileAndImageAttachment;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MessageInputState createState() => MessageInputState();
|
MessageInputState createState() => MessageInputState();
|
||||||
|
|
||||||
@@ -662,6 +658,34 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildFilePickerSection() {
|
Widget _buildFilePickerSection() {
|
||||||
|
var _attachmentContainsFile =
|
||||||
|
_attachments.any((element) => element.attachment.type == 'file');
|
||||||
|
|
||||||
|
Color _getIconColor(int index) {
|
||||||
|
switch (index) {
|
||||||
|
case 0:
|
||||||
|
return _attachmentContainsFile && _attachments.isNotEmpty
|
||||||
|
? Colors.black.withOpacity(0.2)
|
||||||
|
: Colors.black.withOpacity(0.5);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
return !_attachmentContainsFile && _attachments.isNotEmpty
|
||||||
|
? Colors.black.withOpacity(0.2)
|
||||||
|
: Colors.black.withOpacity(0.5);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
return _attachmentContainsFile && _attachments.isNotEmpty
|
||||||
|
? Colors.black.withOpacity(0.2)
|
||||||
|
: Colors.black.withOpacity(0.5);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
return _attachmentContainsFile && _attachments.isNotEmpty
|
||||||
|
? Colors.black.withOpacity(0.2)
|
||||||
|
: Colors.black.withOpacity(0.5);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return AnimatedContainer(
|
return AnimatedContainer(
|
||||||
duration: _animateContainer ? Duration(milliseconds: 300) : Duration.zero,
|
duration: _animateContainer ? Duration(milliseconds: 300) : Duration.zero,
|
||||||
height: _openFilePickerSection ? _filePickerSize : 0,
|
height: _openFilePickerSection ? _filePickerSize : 0,
|
||||||
@@ -675,49 +699,49 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
IconButton(
|
IconButton(
|
||||||
iconSize: 24,
|
iconSize: 24,
|
||||||
icon: StreamSvgIcon.pictures(
|
icon: StreamSvgIcon.pictures(
|
||||||
color: _filePickerIndex == 0
|
color: _getIconColor(0),
|
||||||
? StreamChatTheme.of(context).accentColor
|
|
||||||
: Colors.black.withOpacity(0.5),
|
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: _attachmentContainsFile && _attachments.isNotEmpty
|
||||||
setState(() {
|
? null
|
||||||
_filePickerIndex = 0;
|
: () {
|
||||||
});
|
setState(() {
|
||||||
},
|
_filePickerIndex = 0;
|
||||||
|
});
|
||||||
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
iconSize: 32,
|
iconSize: 32,
|
||||||
icon: StreamSvgIcon.files(
|
icon: StreamSvgIcon.files(
|
||||||
color: _filePickerIndex == 1
|
color: _getIconColor(1),
|
||||||
? StreamChatTheme.of(context).accentColor
|
|
||||||
: Colors.black.withOpacity(0.5),
|
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: !_attachmentContainsFile && _attachments.isNotEmpty
|
||||||
pickFile(DefaultAttachmentTypes.file, false);
|
? null
|
||||||
},
|
: () {
|
||||||
|
pickFile(DefaultAttachmentTypes.file, false);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
iconSize: 24,
|
iconSize: 24,
|
||||||
icon: StreamSvgIcon.camera(
|
icon: StreamSvgIcon.camera(
|
||||||
color: _filePickerIndex == 2
|
color: _getIconColor(2),
|
||||||
? StreamChatTheme.of(context).accentColor
|
|
||||||
: Colors.black.withOpacity(0.5),
|
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: _attachmentContainsFile && _attachments.isNotEmpty
|
||||||
pickFile(DefaultAttachmentTypes.image, true);
|
? null
|
||||||
},
|
: () {
|
||||||
|
pickFile(DefaultAttachmentTypes.image, true);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
padding: const EdgeInsets.all(0),
|
padding: const EdgeInsets.all(0),
|
||||||
iconSize: 24,
|
iconSize: 24,
|
||||||
icon: StreamSvgIcon.record(
|
icon: StreamSvgIcon.record(
|
||||||
color: _filePickerIndex == 3
|
color: _getIconColor(3),
|
||||||
? StreamChatTheme.of(context).accentColor
|
|
||||||
: Colors.black.withOpacity(0.5),
|
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: _attachmentContainsFile && _attachments.isNotEmpty
|
||||||
pickFile(DefaultAttachmentTypes.video, true);
|
? null
|
||||||
},
|
: () {
|
||||||
|
pickFile(DefaultAttachmentTypes.video, true);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -774,6 +798,9 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPickerSection() {
|
Widget _buildPickerSection() {
|
||||||
|
var _attachmentContainsFile =
|
||||||
|
_attachments.any((element) => element.attachment.type == 'file');
|
||||||
|
|
||||||
switch (_filePickerIndex) {
|
switch (_filePickerIndex) {
|
||||||
case 0:
|
case 0:
|
||||||
return FutureBuilder<bool>(
|
return FutureBuilder<bool>(
|
||||||
@@ -786,26 +813,22 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (snapshot.data) {
|
if (snapshot.data) {
|
||||||
return MediaListView(
|
return IgnorePointer(
|
||||||
selectedIds: _attachments.map((e) => e.id).toList(),
|
ignoring: _attachmentContainsFile,
|
||||||
onSelect: (media) async {
|
child: MediaListView(
|
||||||
if (!_attachments
|
selectedIds: _attachments.map((e) => e.id).toList(),
|
||||||
.any((element) => element.id == media.id)) {
|
onSelect: (media) async {
|
||||||
if (widget.enableFileAndImageAttachment) {
|
if (!_attachments
|
||||||
|
.any((element) => element.id == media.id)) {
|
||||||
_addAttachment(media);
|
_addAttachment(media);
|
||||||
} else {
|
} else {
|
||||||
if (!_attachments.any(
|
setState(() {
|
||||||
(element) => element.attachment?.type == 'file')) {
|
_attachments
|
||||||
_addAttachment(media);
|
.removeWhere((element) => element.id == media.id);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
} else {
|
},
|
||||||
setState(() {
|
),
|
||||||
_attachments
|
|
||||||
.removeWhere((element) => element.id == media.id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1581,11 +1604,6 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
bytes: bytes,
|
bytes: bytes,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (_attachments.any((element) => element.attachment.type != 'file') &&
|
|
||||||
!widget.enableFileAndImageAttachment) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileType type;
|
FileType type;
|
||||||
if (fileType == DefaultAttachmentTypes.image) {
|
if (fileType == DefaultAttachmentTypes.image) {
|
||||||
type = FileType.image;
|
type = FileType.image;
|
||||||
|
|||||||
Reference in New Issue
Block a user