From a766e404c585e74ced0db93e8120dce0f2ba1152 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Wed, 30 Dec 2020 21:22:03 +0530 Subject: [PATCH] fix: fixed for all chats --- example/lib/main.dart | 3 +- lib/src/channel_actions_modal.dart | 125 ++++++++++++++++++----------- 2 files changed, 81 insertions(+), 47 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index ba6226c5..c283793a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -374,8 +374,7 @@ class _ChannelListPageState extends State { ), channelWidget: ChannelPage(), onChannelLongPress: (channel) { - if (!channel.isDistinct) - _showChannelDetailsModal(channel); + _showChannelDetailsModal(channel); }, ), ), diff --git a/lib/src/channel_actions_modal.dart b/lib/src/channel_actions_modal.dart index e8891a89..ff8509d7 100644 --- a/lib/src/channel_actions_modal.dart +++ b/lib/src/channel_actions_modal.dart @@ -16,6 +16,8 @@ class ChannelActionsModal extends StatefulWidget { class _ChannelActionsModalState extends State { @override Widget build(BuildContext context) { + var channel = StreamChannel.of(context).channel; + return Material( clipBehavior: Clip.antiAlias, shape: RoundedRectangleBorder( @@ -72,42 +74,73 @@ class _ChannelActionsModalState extends State { SizedBox( height: 17.0, ), - Container( - height: 94.0, - child: ListView.builder( - scrollDirection: Axis.horizontal, - itemCount: snapshot.data.members.length, - itemBuilder: (context, index) { - return Padding( - padding: const EdgeInsets.symmetric(horizontal: 8.0), - child: Column( - children: [ - UserAvatar( - user: snapshot.data.members[index].user, - constraints: BoxConstraints( - maxHeight: 64.0, - maxWidth: 64.0, - ), - borderRadius: BorderRadius.circular(32.0), - ), - SizedBox( - height: 6.0, - ), - Text( - snapshot.data.members[index].user.name, - style: TextStyle( - fontSize: 12.0, - fontWeight: FontWeight.w600, - ), - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ], + if (channel.isDistinct && channel.memberCount == 2) + Column( + children: [ + UserAvatar( + user: snapshot.data.members + .firstWhere((e) => e.user.id != userAsMember.user.id) + .user, + constraints: BoxConstraints( + maxHeight: 64.0, + maxWidth: 64.0, ), - ); - }, + borderRadius: BorderRadius.circular(32.0), + ), + SizedBox( + height: 6.0, + ), + Text( + snapshot.data.members + .firstWhere((e) => e.user.id != userAsMember.user.id) + .user + .name, + style: TextStyle( + fontSize: 12.0, + fontWeight: FontWeight.w600, + ), + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ], + ), + if (!(channel.isDistinct && channel.memberCount == 2)) + Container( + height: 94.0, + child: ListView.builder( + scrollDirection: Axis.horizontal, + itemCount: snapshot.data.members.length, + itemBuilder: (context, index) { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: Column( + children: [ + UserAvatar( + user: snapshot.data.members[index].user, + constraints: BoxConstraints( + maxHeight: 64.0, + maxWidth: 64.0, + ), + borderRadius: BorderRadius.circular(32.0), + ), + SizedBox( + height: 6.0, + ), + Text( + snapshot.data.members[index].user.name, + style: TextStyle( + fontSize: 12.0, + fontWeight: FontWeight.w600, + ), + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ], + ), + ); + }, + ), ), - ), SizedBox( height: 24, ), @@ -118,18 +151,20 @@ class _ChannelActionsModalState extends State { title: 'View Info', onTap: widget.onViewInfoTap, ), - OptionListTile( - leading: StreamSvgIcon.userRemove( - color: Color(0xff7a7a7a), - ), - title: 'Leave Group', - onTap: () async { - var channel = StreamChannel.of(context).channel; + if (!channel.isDistinct) + OptionListTile( + leading: StreamSvgIcon.userRemove( + color: Color(0xff7a7a7a), + ), + title: 'Leave Group', + onTap: () async { + var channel = StreamChannel.of(context).channel; - await channel.removeMembers([StreamChat.of(context).user.id]); - Navigator.pop(context); - }, - ), + await channel + .removeMembers([StreamChat.of(context).user.id]); + Navigator.pop(context); + }, + ), if (isOwner) OptionListTile( leading: StreamSvgIcon.delete(