diff --git a/lib/src/message_list_view.dart b/lib/src/message_list_view.dart index 5c3e67d1..b4373594 100644 --- a/lib/src/message_list_view.dart +++ b/lib/src/message_list_view.dart @@ -67,6 +67,7 @@ class MessageListView extends StatefulWidget { this.showOtherMessageUsername = false, this.showVideoFullScreen = true, this.onMentionTap, + this.onUserAvatarTap, this.onMessageActions, this.attachmentBuilders, this.dateDividerBuilder, @@ -97,6 +98,9 @@ class MessageListView extends StatefulWidget { /// Function called on message mention tap final void Function(User) onMentionTap; + /// Function called on User Avatar tap + final void Function(User) onUserAvatarTap; + /// Function called on message long press final Function(BuildContext, Message) onMessageActions; @@ -164,6 +168,7 @@ class _MessageListViewState extends State { showOtherMessageUsername: widget.showOtherMessageUsername, onMentionTap: widget.onMentionTap, + onUserAvatarTap: widget.onUserAvatarTap, onMessageActions: widget.onMessageActions, attachmentBuilders: widget.attachmentBuilders, ), @@ -227,6 +232,7 @@ class _MessageListViewState extends State { showOtherMessageUsername: widget.showOtherMessageUsername, showVideoFullScreen: widget.showVideoFullScreen, onMentionTap: widget.onMentionTap, + onUserAvatarTap: widget.onUserAvatarTap, onMessageActions: widget.onMessageActions, attachmentBuilders: widget.attachmentBuilders, ); @@ -314,6 +320,7 @@ class _MessageListViewState extends State { showVideoFullScreen: widget.showVideoFullScreen, showOtherMessageUsername: widget.showOtherMessageUsername, onMentionTap: widget.onMentionTap, + onUserAvatarTap: widget.onUserAvatarTap, onMessageActions: widget.onMessageActions, attachmentBuilders: widget.attachmentBuilders, ); @@ -354,6 +361,7 @@ class _MessageListViewState extends State { showVideoFullScreen: widget.showVideoFullScreen, showOtherMessageUsername: widget.showOtherMessageUsername, onMentionTap: widget.onMentionTap, + onUserAvatarTap: widget.onUserAvatarTap, onMessageActions: widget.onMessageActions, attachmentBuilders: widget.attachmentBuilders, ); diff --git a/lib/src/message_widget.dart b/lib/src/message_widget.dart index 49055937..af5173d9 100644 --- a/lib/src/message_widget.dart +++ b/lib/src/message_widget.dart @@ -41,6 +41,7 @@ class MessageWidget extends StatefulWidget { @required this.message, @required this.nextMessage, this.onThreadTap, + this.onUserAvatarTap, this.onMessageActions, this.isParent = false, this.onMentionTap, @@ -70,6 +71,9 @@ class MessageWidget extends StatefulWidget { /// The function called when tapping on replies final void Function(Message) onThreadTap; + /// The function called when tapping on UserAvatar + final void Function(User) onUserAvatarTap; + /// True if this is the parent of the thread being showed final bool isParent; @@ -161,7 +165,10 @@ class _MessageWidgetState extends State ), child: Row( children: [ - UserAvatar(user: widget.message.user), + UserAvatar( + user: widget.message.user, + onTap: widget.onUserAvatarTap, + ), if (_isMyMessage && widget.nextMessage == null) SendingIndicator( message: widget.message, diff --git a/lib/src/user_avatar.dart b/lib/src/user_avatar.dart index 2377411e..8ea9a525 100644 --- a/lib/src/user_avatar.dart +++ b/lib/src/user_avatar.dart @@ -9,41 +9,55 @@ class UserAvatar extends StatelessWidget { Key key, @required this.user, this.constraints, + this.onTap, }) : super(key: key); final User user; final BoxConstraints constraints; + final void Function(User) onTap; @override Widget build(BuildContext context) { - return ClipRRect( - borderRadius: - StreamChatTheme.of(context).ownMessageTheme.avatarTheme.borderRadius, - child: Container( - constraints: constraints ?? - StreamChatTheme.of(context).ownMessageTheme.avatarTheme.constraints, - decoration: BoxDecoration( - color: StreamChatTheme.of(context).accentColor, - ), - child: user.extraData?.containsKey('image') ?? false - ? CachedNetworkImage( - imageUrl: user.extraData['image'], - errorWidget: (_, __, ___) { - return Center( - child: Text( - user.extraData?.containsKey('name') ?? false - ? user.extraData['name'][0] - : '', - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.bold, + return GestureDetector( + onTap: () { + if (onTap != null) { + onTap(user); + } + }, + child: ClipRRect( + borderRadius: StreamChatTheme.of(context) + .ownMessageTheme + .avatarTheme + .borderRadius, + child: Container( + constraints: constraints ?? + StreamChatTheme.of(context) + .ownMessageTheme + .avatarTheme + .constraints, + decoration: BoxDecoration( + color: StreamChatTheme.of(context).accentColor, + ), + child: user.extraData?.containsKey('image') ?? false + ? CachedNetworkImage( + imageUrl: user.extraData['image'], + errorWidget: (_, __, ___) { + return Center( + child: Text( + user.extraData?.containsKey('name') ?? false + ? user.extraData['name'][0] + : '', + style: TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + ), ), - ), - ); - }, - fit: BoxFit.cover, - ) - : StreamChatTheme.of(context).defaultUserImage(context, user), + ); + }, + fit: BoxFit.cover, + ) + : StreamChatTheme.of(context).defaultUserImage(context, user), + ), ), ); }