fix: Added boolean for picking one thing at a time -_-
This commit is contained in:
committed by
Salvatore Giordano
parent
a846048ef1
commit
9918a4bfde
+51
-33
@@ -108,6 +108,7 @@ 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
|
||||||
@@ -156,6 +157,9 @@ 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();
|
||||||
|
|
||||||
@@ -787,7 +791,14 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
onSelect: (media) async {
|
onSelect: (media) async {
|
||||||
if (!_attachments
|
if (!_attachments
|
||||||
.any((element) => element.id == media.id)) {
|
.any((element) => element.id == media.id)) {
|
||||||
_addAttachment(media);
|
if (widget.enableFileAndImageAttachment) {
|
||||||
|
_addAttachment(media);
|
||||||
|
} else {
|
||||||
|
if (!_attachments.any(
|
||||||
|
(element) => element.attachment?.type == 'file')) {
|
||||||
|
_addAttachment(media);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setState(() {
|
setState(() {
|
||||||
_attachments
|
_attachments
|
||||||
@@ -850,7 +861,7 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (file.size > _kMaxAttachmentSize) {
|
if (file.size > _kMaxAttachmentSize) {
|
||||||
if (medium.type == AssetType.video) {
|
if (medium?.type == AssetType.video) {
|
||||||
final mediaInfo = await CompressVideoService.compressVideo(file.path);
|
final mediaInfo = await CompressVideoService.compressVideo(file.path);
|
||||||
|
|
||||||
if (mediaInfo.filesize / (1024 * 1024) > _kMaxAttachmentSize) {
|
if (mediaInfo.filesize / (1024 * 1024) > _kMaxAttachmentSize) {
|
||||||
@@ -1203,42 +1214,44 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
? Container()
|
? Container()
|
||||||
: Column(
|
: Column(
|
||||||
children: [
|
children: [
|
||||||
LimitedBox(
|
if (_attachments.any((e) => e.attachment?.type == 'file'))
|
||||||
maxHeight: 73.0,
|
LimitedBox(
|
||||||
child: ListView(
|
maxHeight: 73.0,
|
||||||
scrollDirection: Axis.horizontal,
|
child: ListView(
|
||||||
children: _attachments
|
scrollDirection: Axis.horizontal,
|
||||||
.where((e) => e.attachment.type == 'file')
|
children: _attachments
|
||||||
.map(
|
.where((e) => e.attachment?.type == 'file')
|
||||||
(e) => Padding(
|
.map(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
(e) => Padding(
|
||||||
child: FileAttachment(
|
padding:
|
||||||
attachment: e.attachment,
|
const EdgeInsets.symmetric(horizontal: 4.0),
|
||||||
size: Size(
|
child: FileAttachment(
|
||||||
MediaQuery.of(context).size.width * 0.55,
|
attachment: e.attachment,
|
||||||
MediaQuery.of(context).size.height * 0.3,
|
size: Size(
|
||||||
),
|
MediaQuery.of(context).size.width * 0.55,
|
||||||
trailing: IconButton(
|
MediaQuery.of(context).size.height * 0.3,
|
||||||
icon: StreamSvgIcon.close_small(),
|
),
|
||||||
onPressed: () {
|
trailing: IconButton(
|
||||||
setState(() {
|
icon: StreamSvgIcon.close_small(),
|
||||||
_attachments.remove(e);
|
onPressed: () {
|
||||||
});
|
setState(() {
|
||||||
},
|
_attachments.remove(e);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
)
|
.toList(),
|
||||||
.toList(),
|
),
|
||||||
),
|
),
|
||||||
),
|
if (_attachments.any((e) => e.attachment?.type != 'file'))
|
||||||
if (_attachments.any((e) => e.attachment.type != 'file'))
|
|
||||||
LimitedBox(
|
LimitedBox(
|
||||||
maxHeight: 104.0,
|
maxHeight: 104.0,
|
||||||
child: ListView(
|
child: ListView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
children: _attachments
|
children: _attachments
|
||||||
.where((e) => e.attachment.type != 'file')
|
.where((e) => e.attachment?.type != 'file')
|
||||||
.map(
|
.map(
|
||||||
(attachment) => Padding(
|
(attachment) => Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
@@ -1312,9 +1325,9 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
|
|
||||||
Widget _buildAttachment(_SendingAttachment attachment) {
|
Widget _buildAttachment(_SendingAttachment attachment) {
|
||||||
if (widget.attachmentThumbnailBuilders
|
if (widget.attachmentThumbnailBuilders
|
||||||
?.containsKey(attachment.attachment.type) ==
|
?.containsKey(attachment.attachment?.type) ==
|
||||||
true) {
|
true) {
|
||||||
return widget.attachmentThumbnailBuilders[attachment.attachment.type](
|
return widget.attachmentThumbnailBuilders[attachment.attachment?.type](
|
||||||
context,
|
context,
|
||||||
attachment,
|
attachment,
|
||||||
);
|
);
|
||||||
@@ -1324,7 +1337,7 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
return SizedBox();
|
return SizedBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (attachment.attachment.type) {
|
switch (attachment.attachment?.type) {
|
||||||
case 'image':
|
case 'image':
|
||||||
case 'giphy':
|
case 'giphy':
|
||||||
return attachment.file != null
|
return attachment.file != null
|
||||||
@@ -1568,6 +1581,11 @@ 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