add editMessageInputBuilder to customize the messageinput while editing messages
This commit is contained in:
@@ -92,7 +92,7 @@ class MessageInput extends StatefulWidget {
|
|||||||
this.textEditingController,
|
this.textEditingController,
|
||||||
this.actions,
|
this.actions,
|
||||||
this.actionsLocation = ActionsLocation.left,
|
this.actionsLocation = ActionsLocation.left,
|
||||||
this.attachmentThumbnailBuilder,
|
this.attachmentThumbnailBuilders,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Message to edit
|
/// Message to edit
|
||||||
@@ -135,8 +135,8 @@ class MessageInput extends StatefulWidget {
|
|||||||
/// The location of the custom actions
|
/// The location of the custom actions
|
||||||
final ActionsLocation actionsLocation;
|
final ActionsLocation actionsLocation;
|
||||||
|
|
||||||
/// Map that defines a builder for an attachment type
|
/// Map that defines a thumbnail builder for an attachment type
|
||||||
final Map<String, AttachmentThumbnailBuilder> attachmentThumbnailBuilder;
|
final Map<String, AttachmentThumbnailBuilder> attachmentThumbnailBuilders;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MessageInputState createState() => MessageInputState();
|
MessageInputState createState() => MessageInputState();
|
||||||
@@ -547,13 +547,10 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildAttachment(_SendingAttachment attachment) {
|
Widget _buildAttachment(_SendingAttachment attachment) {
|
||||||
print('attachment.attachment.toJson(): ${attachment.attachment.toJson()}');
|
if (widget.attachmentThumbnailBuilders
|
||||||
print(
|
|
||||||
'widget.attachmentThumbnailBuilder: ${widget.attachmentThumbnailBuilder}');
|
|
||||||
if (widget.attachmentThumbnailBuilder
|
|
||||||
?.containsKey(attachment.attachment.type) ==
|
?.containsKey(attachment.attachment.type) ==
|
||||||
true) {
|
true) {
|
||||||
return widget.attachmentThumbnailBuilder[attachment.attachment.type](
|
return widget.attachmentThumbnailBuilders[attachment.attachment.type](
|
||||||
context,
|
context,
|
||||||
attachment,
|
attachment,
|
||||||
);
|
);
|
||||||
@@ -897,6 +894,10 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
return sendingFuture.whenComplete(() {
|
return sendingFuture.whenComplete(() {
|
||||||
if (widget.onMessageSent != null) {
|
if (widget.onMessageSent != null) {
|
||||||
widget.onMessageSent(message);
|
widget.onMessageSent(message);
|
||||||
|
} else {
|
||||||
|
if (widget.editMessage != null) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -958,7 +959,6 @@ class MessageInputState extends State<MessageInput> {
|
|||||||
_messageIsPresent = true;
|
_messageIsPresent = true;
|
||||||
|
|
||||||
message.attachments?.forEach((attachment) {
|
message.attachments?.forEach((attachment) {
|
||||||
print('attachment: ${attachment.toJson()}');
|
|
||||||
_attachments.add(_SendingAttachment(
|
_attachments.add(_SendingAttachment(
|
||||||
attachment: attachment,
|
attachment: attachment,
|
||||||
uploaded: true,
|
uploaded: true,
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ class MessageListView extends StatefulWidget {
|
|||||||
this.attachmentBuilders,
|
this.attachmentBuilders,
|
||||||
this.dateDividerBuilder,
|
this.dateDividerBuilder,
|
||||||
this.showAvatar = true,
|
this.showAvatar = true,
|
||||||
|
this.editMessageInputBuilder,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Function used to build a custom message widget
|
/// Function used to build a custom message widget
|
||||||
@@ -115,6 +116,9 @@ class MessageListView extends StatefulWidget {
|
|||||||
/// if true shows the user avatar
|
/// if true shows the user avatar
|
||||||
final bool showAvatar;
|
final bool showAvatar;
|
||||||
|
|
||||||
|
/// Builder used to build the message input to edit a message
|
||||||
|
final Widget Function(BuildContext, Message) editMessageInputBuilder;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_MessageListViewState createState() => _MessageListViewState();
|
_MessageListViewState createState() => _MessageListViewState();
|
||||||
}
|
}
|
||||||
@@ -177,6 +181,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
onMessageActions: widget.onMessageActions,
|
onMessageActions: widget.onMessageActions,
|
||||||
attachmentBuilders: widget.attachmentBuilders,
|
attachmentBuilders: widget.attachmentBuilders,
|
||||||
showAvatar: widget.showAvatar,
|
showAvatar: widget.showAvatar,
|
||||||
|
editMessageInputBuilder: widget.editMessageInputBuilder,
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 32),
|
padding: const EdgeInsets.symmetric(horizontal: 32),
|
||||||
@@ -243,6 +248,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
onMessageActions: widget.onMessageActions,
|
onMessageActions: widget.onMessageActions,
|
||||||
attachmentBuilders: widget.attachmentBuilders,
|
attachmentBuilders: widget.attachmentBuilders,
|
||||||
showAvatar: widget.showAvatar,
|
showAvatar: widget.showAvatar,
|
||||||
|
editMessageInputBuilder: widget.editMessageInputBuilder,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -337,6 +343,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
onMessageActions: widget.onMessageActions,
|
onMessageActions: widget.onMessageActions,
|
||||||
attachmentBuilders: widget.attachmentBuilders,
|
attachmentBuilders: widget.attachmentBuilders,
|
||||||
showAvatar: widget.showAvatar,
|
showAvatar: widget.showAvatar,
|
||||||
|
editMessageInputBuilder: widget.editMessageInputBuilder,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,6 +386,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
onMessageActions: widget.onMessageActions,
|
onMessageActions: widget.onMessageActions,
|
||||||
attachmentBuilders: widget.attachmentBuilders,
|
attachmentBuilders: widget.attachmentBuilders,
|
||||||
showAvatar: widget.showAvatar,
|
showAvatar: widget.showAvatar,
|
||||||
|
editMessageInputBuilder: widget.editMessageInputBuilder,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
-15
@@ -51,6 +51,7 @@ class MessageWidget extends StatefulWidget {
|
|||||||
this.showVideoFullScreen = true,
|
this.showVideoFullScreen = true,
|
||||||
this.attachmentBuilders,
|
this.attachmentBuilders,
|
||||||
this.showAvatar = true,
|
this.showAvatar = true,
|
||||||
|
this.editMessageInputBuilder,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// Function called on mention tap
|
/// Function called on mention tap
|
||||||
@@ -89,6 +90,9 @@ class MessageWidget extends StatefulWidget {
|
|||||||
/// if true shows the user avatar
|
/// if true shows the user avatar
|
||||||
final bool showAvatar;
|
final bool showAvatar;
|
||||||
|
|
||||||
|
/// Builder used to build the message input to edit a message
|
||||||
|
final Widget Function(BuildContext, Message) editMessageInputBuilder;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_MessageWidgetState createState() => _MessageWidgetState();
|
_MessageWidgetState createState() => _MessageWidgetState();
|
||||||
}
|
}
|
||||||
@@ -723,21 +727,23 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
bottom: MediaQuery.of(context).viewInsets.bottom,
|
bottom: MediaQuery.of(context).viewInsets.bottom,
|
||||||
),
|
),
|
||||||
child: MessageInput(
|
child: widget.editMessageInputBuilder != null
|
||||||
editMessage: widget.message,
|
? widget.editMessageInputBuilder(context, widget.message)
|
||||||
parentMessage: widget.isParent
|
: MessageInput(
|
||||||
? StreamChannel.of(context)
|
editMessage: widget.message,
|
||||||
.channel
|
parentMessage: widget.isParent
|
||||||
.state
|
? StreamChannel.of(context)
|
||||||
.messages
|
.channel
|
||||||
.firstWhere((message) =>
|
.state
|
||||||
message.id == widget.message.parentId)
|
.messages
|
||||||
: null,
|
.firstWhere((message) =>
|
||||||
onMessageSent: (_) {
|
message.id == widget.message.parentId)
|
||||||
FocusScope.of(context).unfocus();
|
: null,
|
||||||
Navigator.pop(context);
|
onMessageSent: (_) {
|
||||||
},
|
FocusScope.of(context).unfocus();
|
||||||
),
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user