From ceaf30e5454a8e12337e3eeca09471037a34bbb8 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Mon, 31 May 2021 11:30:51 +0530 Subject: [PATCH] feat: Added list of actions to channel_list_view.dart --- .../lib/src/channel_list_view.dart | 109 ++++++++++-------- 1 file changed, 58 insertions(+), 51 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/channel_list_view.dart b/packages/stream_chat_flutter/lib/src/channel_list_view.dart index 1d0a4966..8d7c833a 100644 --- a/packages/stream_chat_flutter/lib/src/channel_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/channel_list_view.dart @@ -80,6 +80,7 @@ class ChannelListView extends StatefulWidget { this.listBuilder, this.onMoreDetailsPressed, this.onDeletePressed, + this.swipeActions, }) : super(key: key); /// If true a default swipe to action behaviour will be added to this widget @@ -166,6 +167,9 @@ class ChannelListView extends StatefulWidget { /// Callback used when the delete slidable option is pressed final VoidCallback? onDeletePressed; + /// Actions shown when list tile is swiped + final List? swipeActions; + @override _ChannelListViewState createState() => _ChannelListViewState(); } @@ -473,61 +477,64 @@ class _ChannelListViewState extends State { enabled: widget.swipeToAction, actionPane: const SlidableBehindActionPane(), actionExtentRatio: 0.12, - secondaryActions: [ - IconSlideAction( - color: backgroundColor, - icon: Icons.more_horiz, - onTap: widget.onMoreDetailsPressed ?? () { - showModalBottomSheet( - clipBehavior: Clip.hardEdge, - shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(32), - topRight: Radius.circular(32), - ), - ), - context: context, - builder: (context) => StreamChannel( - channel: channel, - child: ChannelBottomSheet( - onViewInfoTap: () { - widget.onViewInfoTap?.call(channel); + secondaryActions: widget.swipeActions ?? + [ + IconSlideAction( + color: backgroundColor, + icon: Icons.more_horiz, + onTap: widget.onMoreDetailsPressed ?? + () { + showModalBottomSheet( + clipBehavior: Clip.hardEdge, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.only( + topLeft: Radius.circular(32), + topRight: Radius.circular(32), + ), + ), + context: context, + builder: (context) => StreamChannel( + channel: channel, + child: ChannelBottomSheet( + onViewInfoTap: () { + widget.onViewInfoTap?.call(channel); + }, + ), + ), + ); }, - ), - ), - ); - }, - ), - if ([ - 'admin', - 'owner', - ].contains(channel.state!.members - .firstWhereOrNull( - (m) => m.userId == channel.client.state.user?.id) - ?.role)) - IconSlideAction( - color: backgroundColor, - iconWidget: StreamSvgIcon.delete( - color: chatThemeData.colorTheme.accentRed, ), - onTap: widget.onDeletePressed ?? () async { - final res = await showConfirmationDialog( - context, - title: 'Delete Conversation', - okText: 'DELETE', - question: - 'Are you sure you want to delete this conversation?', - cancelText: 'CANCEL', - icon: StreamSvgIcon.delete( + if ([ + 'admin', + 'owner', + ].contains(channel.state!.members + .firstWhereOrNull( + (m) => m.userId == channel.client.state.user?.id) + ?.role)) + IconSlideAction( + color: backgroundColor, + iconWidget: StreamSvgIcon.delete( color: chatThemeData.colorTheme.accentRed, ), - ); - if (res == true) { - await channel.delete(); - } - }, - ), - ], + onTap: widget.onDeletePressed ?? + () async { + final res = await showConfirmationDialog( + context, + title: 'Delete Conversation', + okText: 'DELETE', + question: + 'Are you sure you want to delete this conversation?', + cancelText: 'CANCEL', + icon: StreamSvgIcon.delete( + color: chatThemeData.colorTheme.accentRed, + ), + ); + if (res == true) { + await channel.delete(); + } + }, + ), + ], child: Container( color: chatThemeData.colorTheme.whiteSnow, child: widget.channelPreviewBuilder?.call(context, channel) ??