Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to listen onTap of the channel message list avatar. #64

Closed
yswtrue opened this issue Jul 28, 2020 · 2 comments
Closed

How to listen onTap of the channel message list avatar. #64

yswtrue opened this issue Jul 28, 2020 · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@yswtrue
Copy link

yswtrue commented Jul 28, 2020

How can I listen on the tap event of the message list avatar, such as click avatar to jump to user profile page? I couldn't find the param.

gz#4659

@imtoori
Copy link
Contributor

imtoori commented Jul 28, 2020

you can pass a MessageBuilder to the MessageListView
It has a parameter called onUserAvatarTap

Something like this:

  Widget _messageBuilder(
    BuildContext context,
    MessageDetails details,
    List<Message> messages,
  ) {
    final message = details.message;
    final color = details.isMyMessage ? Colors.blueGrey : Colors.blue;
    if (message.isSystem) {
      return SystemMessage(
        message: message,
      );
    }
    return MessageWidget(
      message: message,
      messageTheme: details.isMyMessage
          ? StreamChatTheme.of(context).ownMessageTheme
          : StreamChatTheme.of(context).otherMessageTheme,
      borderSide: BorderSide(
        color: color,
        width: 2,
      ),
      padding: const EdgeInsets.all(2),
      attachmentBorderSide: BorderSide(
        color: color,
        width: 2,
      ),
      attachmentPadding: EdgeInsets.all(8),
      borderRadiusGeometry: BorderRadius.vertical(
        top: !details.isLastUser ? Radius.circular(16) : Radius.zero,
        bottom: !details.isNextUser ? Radius.circular(16) : Radius.zero,
      ),
      showSendingIndicator: DisplayWidget.gone,
      reverse: false,
      showUserAvatar:
          details.isNextUser ? DisplayWidget.hide : DisplayWidget.show,
      showTimestamp: !details.isNextUser,
      showUsername: !details.isNextUser,
      showReactions: false,
      showReplyIndicator: false,
      onUserAvatarTap: (user) {
        print('TAPPED USER ${user.name}');
      },
    );
  }

There is also an example in the /example folder, but we're planning to write more docs about this and other use cases

@imtoori imtoori self-assigned this Jul 28, 2020
@imtoori imtoori added the documentation Improvements or additions to documentation label Jul 28, 2020
@yswtrue
Copy link
Author

yswtrue commented Jul 28, 2020

    final message = details.message;
    final color = details.isMyMessage ? Colors.blueGrey : Colors.blue;
    if (message.isSystem) {
      return SystemMessage(
        message: message,
      );
    }
    return MessageWidget(
      message: message,
      messageTheme: details.isMyMessage
          ? StreamChatTheme.of(context).ownMessageTheme
          : StreamChatTheme.of(context).otherMessageTheme,
      borderSide: BorderSide(
        color: color,
        width: 2,
      ),
      padding: const EdgeInsets.all(2),
      attachmentBorderSide: BorderSide(
        color: color,
        width: 2,
      ),
      attachmentPadding: EdgeInsets.all(8),
      borderRadiusGeometry: BorderRadius.vertical(
        top: !details.isLastUser ? Radius.circular(16) : Radius.zero,
        bottom: !details.isNextUser ? Radius.circular(16) : Radius.zero,
      ),
      showSendingIndicator: DisplayWidget.gone,
      reverse: false,
      showUserAvatar:
          details.isNextUser ? DisplayWidget.hide : DisplayWidget.show,
      showTimestamp: !details.isNextUser,
      showUsername: !details.isNextUser,
      showReactions: false,
      showReplyIndicator: false,
      onUserAvatarTap: (user) {
        print('TAPPED USER ${user.name}');
      },
    );

It worked, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants