From 061962ea8bd0263895441867674699622475470d Mon Sep 17 00:00:00 2001 From: Luis Pulido Date: Thu, 23 Apr 2020 11:41:07 -0400 Subject: [PATCH 1/3] Added onUserAvatarTap --- lib/src/message_list_view.dart | 8 ++++++++ lib/src/message_widget.dart | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/src/message_list_view.dart b/lib/src/message_list_view.dart index 468bf054..13ea7233 100644 --- a/lib/src/message_list_view.dart +++ b/lib/src/message_list_view.dart @@ -65,6 +65,7 @@ class MessageListView extends StatefulWidget { this.showOtherMessageUsername = false, this.showVideoFullScreen = true, this.onMentionTap, + this.onUserAvatarTap, this.onMessageActions, }) : super(key: key); @@ -93,6 +94,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; @@ -154,6 +158,7 @@ class _MessageListViewState extends State { showOtherMessageUsername: widget.showOtherMessageUsername, onMentionTap: widget.onMentionTap, + onUserAvatarTap: widget.onUserAvatarTap, onMessageActions: widget.onMessageActions, ), Padding( @@ -216,6 +221,7 @@ class _MessageListViewState extends State { showOtherMessageUsername: widget.showOtherMessageUsername, showVideoFullScreen: widget.showVideoFullScreen, onMentionTap: widget.onMentionTap, + onUserAvatarTap: widget.onUserAvatarTap, onMessageActions: widget.onMessageActions, ); } @@ -363,6 +369,7 @@ class _MessageListViewState extends State { showVideoFullScreen: widget.showVideoFullScreen, showOtherMessageUsername: widget.showOtherMessageUsername, onMentionTap: widget.onMentionTap, + onUserAvatarTap: widget.onUserAvatarTap, onMessageActions: widget.onMessageActions, ); } @@ -402,6 +409,7 @@ class _MessageListViewState extends State { showVideoFullScreen: widget.showVideoFullScreen, showOtherMessageUsername: widget.showOtherMessageUsername, onMentionTap: widget.onMentionTap, + onUserAvatarTap: widget.onUserAvatarTap, onMessageActions: widget.onMessageActions, ); } diff --git a/lib/src/message_widget.dart b/lib/src/message_widget.dart index 18a8cfdd..43def300 100644 --- a/lib/src/message_widget.dart +++ b/lib/src/message_widget.dart @@ -35,6 +35,7 @@ class MessageWidget extends StatefulWidget { @required this.message, @required this.nextMessage, this.onThreadTap, + this.onUserAvatarTap, this.onMessageActions, this.isParent = false, this.onMentionTap, @@ -63,6 +64,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; @@ -151,7 +155,14 @@ class _MessageWidgetState extends State ), child: Row( children: [ - UserAvatar(user: widget.message.user), + GestureDetector( + onTap: () { + if (widget.onUserAvatarTap != null) { + widget.onUserAvatarTap(widget.message.user); + } + }, + child: UserAvatar(user: widget.message.user), + ), if (_isMyMessage && widget.nextMessage == null && (widget.message.status == MessageSendingStatus.SENT || From c5ba6dc3902fbc1e36e45675b420f1fa98012a53 Mon Sep 17 00:00:00 2001 From: Luis Pulido Date: Thu, 23 Apr 2020 12:31:01 -0400 Subject: [PATCH 2/3] moved tap logic to UserAvatar Widget --- lib/src/message_widget.dart | 10 ++---- lib/src/user_avatar.dart | 68 ++++++++++++++++++++++--------------- 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/lib/src/message_widget.dart b/lib/src/message_widget.dart index 43def300..806a666a 100644 --- a/lib/src/message_widget.dart +++ b/lib/src/message_widget.dart @@ -155,13 +155,9 @@ class _MessageWidgetState extends State ), child: Row( children: [ - GestureDetector( - onTap: () { - if (widget.onUserAvatarTap != null) { - widget.onUserAvatarTap(widget.message.user); - } - }, - child: UserAvatar(user: widget.message.user), + UserAvatar( + user: widget.message.user, + onUserAvatarTap: widget.onUserAvatarTap, ), if (_isMyMessage && widget.nextMessage == null && diff --git a/lib/src/user_avatar.dart b/lib/src/user_avatar.dart index 2377411e..94a5533d 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.onUserAvatarTap, }) : super(key: key); final User user; final BoxConstraints constraints; + final void Function(User) onUserAvatarTap; @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 (onUserAvatarTap != null) { + onUserAvatarTap(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), + ), ), ); } From c88ae78ced8351f464f0c2263952f2129e846492 Mon Sep 17 00:00:00 2001 From: Luis Pulido Date: Fri, 24 Apr 2020 09:13:02 -0400 Subject: [PATCH 3/3] renamed method to onTap --- lib/src/message_widget.dart | 2 +- lib/src/user_avatar.dart | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/message_widget.dart b/lib/src/message_widget.dart index 806a666a..5445fc59 100644 --- a/lib/src/message_widget.dart +++ b/lib/src/message_widget.dart @@ -157,7 +157,7 @@ class _MessageWidgetState extends State children: [ UserAvatar( user: widget.message.user, - onUserAvatarTap: widget.onUserAvatarTap, + onTap: widget.onUserAvatarTap, ), if (_isMyMessage && widget.nextMessage == null && diff --git a/lib/src/user_avatar.dart b/lib/src/user_avatar.dart index 94a5533d..8ea9a525 100644 --- a/lib/src/user_avatar.dart +++ b/lib/src/user_avatar.dart @@ -9,19 +9,19 @@ class UserAvatar extends StatelessWidget { Key key, @required this.user, this.constraints, - this.onUserAvatarTap, + this.onTap, }) : super(key: key); final User user; final BoxConstraints constraints; - final void Function(User) onUserAvatarTap; + final void Function(User) onTap; @override Widget build(BuildContext context) { return GestureDetector( onTap: () { - if (onUserAvatarTap != null) { - onUserAvatarTap(user); + if (onTap != null) { + onTap(user); } }, child: ClipRRect(