diff --git a/packages/stream_chat_flutter/lib/src/message_list_view.dart b/packages/stream_chat_flutter/lib/src/message_list_view.dart index 18675846..d6eb0148 100644 --- a/packages/stream_chat_flutter/lib/src/message_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/message_list_view.dart @@ -136,6 +136,8 @@ class MessageListView extends StatefulWidget { this.messageListBuilder, this.errorWidgetBuilder, this.customAttachmentBuilders, + this.onMessageTap, + this.onSystemMessageTap, }) : super(key: key); /// Function used to build a custom message widget @@ -216,6 +218,12 @@ class MessageListView extends StatefulWidget { /// Please change this in the [MessageWidget] if you are using a custom implementation final Map customAttachmentBuilders; + /// Called when any message is tapped except a system message (use [onSystemMessageTap] instead) + final void Function(Message) onMessageTap; + + /// Called when system message is tapped + final void Function(Message) onSystemMessageTap; + @override _MessageListViewState createState() => _MessageListViewState(); } @@ -364,6 +372,9 @@ class _MessageListViewState extends State { childAnchor: Alignment.topCenter, message: statusString, child: LazyLoadScrollView( + onPageScrollStart: () { + FocusScope.of(context).unfocus(); + }, onStartOfPage: () async { _inBetweenList = false; if (!_upToDate) { @@ -812,6 +823,12 @@ class _MessageListViewState extends State { } }, customAttachmentBuilders: widget.customAttachmentBuilders, + onMessageTap: (message) { + if (widget.onMessageTap != null) { + widget.onMessageTap(message); + } + FocusScope.of(context).unfocus(); + }, ); } @@ -825,6 +842,12 @@ class _MessageListViewState extends State { SystemMessage( key: ValueKey('MESSAGE-${message.id}'), message: message, + onMessageTap: (message) { + if (widget.onSystemMessageTap != null) { + widget.onSystemMessageTap(message); + } + FocusScope.of(context).unfocus(); + }, ); } @@ -974,6 +997,12 @@ class _MessageListViewState extends State { } }, customAttachmentBuilders: widget.customAttachmentBuilders, + onMessageTap: (message) { + if (widget.onMessageTap != null) { + widget.onMessageTap(message); + } + FocusScope.of(context).unfocus(); + }, ); if (!message.isDeleted && diff --git a/packages/stream_chat_flutter/lib/src/message_widget.dart b/packages/stream_chat_flutter/lib/src/message_widget.dart index 91c53566..1bc9d2c9 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget.dart @@ -143,6 +143,9 @@ class MessageWidget extends StatefulWidget { /// Function called when quotedMessage is tapped final OnQuotedMessageTap onQuotedMessageTap; + /// Function called when message is tapped + final void Function(Message) onMessageTap; + /// MessageWidget({ Key key, @@ -157,6 +160,7 @@ class MessageWidget extends StatefulWidget { this.borderRadiusGeometry, this.attachmentBorderRadiusGeometry, this.onMentionTap, + this.onMessageTap, this.showReactionPickerIndicator = false, this.showUserAvatar = DisplayWidget.show, this.showSendingIndicator = true, @@ -311,6 +315,9 @@ class _MessageWidgetState extends State type: MaterialType.transparency, child: Portal( child: InkWell( + onTap: () { + widget.onMessageTap(widget.message); + }, onLongPress: widget.message.isDeleted && !isFailedState ? null : () => onLongPress(context),