From 765ca6034396cdf8927602e1540c4a38a27953aa Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Mon, 31 May 2021 11:16:40 +0530 Subject: [PATCH 1/7] feat: Added callbacks for default slidable options --- .../lib/src/channel_list_view.dart | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 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 766fe4ba..1d0a4966 100644 --- a/packages/stream_chat_flutter/lib/src/channel_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/channel_list_view.dart @@ -78,6 +78,8 @@ class ChannelListView extends StatefulWidget { this.emptyBuilder, this.loadingBuilder, this.listBuilder, + this.onMoreDetailsPressed, + this.onDeletePressed, }) : super(key: key); /// If true a default swipe to action behaviour will be added to this widget @@ -158,6 +160,12 @@ class ChannelListView extends StatefulWidget { /// The builder used when the channel list is empty. final WidgetBuilder? emptyBuilder; + /// Callback used when the more details slidable option is pressed + final VoidCallback? onMoreDetailsPressed; + + /// Callback used when the delete slidable option is pressed + final VoidCallback? onDeletePressed; + @override _ChannelListViewState createState() => _ChannelListViewState(); } @@ -469,7 +477,7 @@ class _ChannelListViewState extends State { IconSlideAction( color: backgroundColor, icon: Icons.more_horiz, - onTap: () { + onTap: widget.onMoreDetailsPressed ?? () { showModalBottomSheet( clipBehavior: Clip.hardEdge, shape: const RoundedRectangleBorder( @@ -502,7 +510,7 @@ class _ChannelListViewState extends State { iconWidget: StreamSvgIcon.delete( color: chatThemeData.colorTheme.accentRed, ), - onTap: () async { + onTap: widget.onDeletePressed ?? () async { final res = await showConfirmationDialog( context, title: 'Delete Conversation', From ceaf30e5454a8e12337e3eeca09471037a34bbb8 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Mon, 31 May 2021 11:30:51 +0530 Subject: [PATCH 2/7] 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) ?? From ba0b525255a3b5341311a8a58da344768a3628c9 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Mon, 31 May 2021 11:37:48 +0530 Subject: [PATCH 3/7] removed swipe actions list --- .../lib/src/channel_list_view.dart | 117 +++++++++--------- 1 file changed, 56 insertions(+), 61 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 8d7c833a..46e2ebf9 100644 --- a/packages/stream_chat_flutter/lib/src/channel_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/channel_list_view.dart @@ -80,7 +80,6 @@ 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 @@ -167,9 +166,6 @@ 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(); } @@ -477,64 +473,63 @@ class _ChannelListViewState extends State { enabled: widget.swipeToAction, actionPane: const SlidableBehindActionPane(), actionExtentRatio: 0.12, - 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); - }, - ), - ), - ); - }, + 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); + }, + ), + ), + ); + }, + ), + 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 ([ - '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( - 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) ?? From f75e50d651a6573e1105cd442c8e4118af99a96b Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Mon, 31 May 2021 14:21:17 +0530 Subject: [PATCH 4/7] added swipe actions list --- .../lib/src/channel_list_view.dart | 135 ++++++++++-------- 1 file changed, 79 insertions(+), 56 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 46e2ebf9..1478c745 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; + /// List of actions for slidable + final List? swipeActions; + @override _ChannelListViewState createState() => _ChannelListViewState(); } @@ -473,63 +477,70 @@ 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); - }, - ), - ), - ); - }, - ), - 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, + secondaryActions: widget.swipeActions + ?.map((e) => IconSlideAction( + color: e.color, + iconWidget: e.iconWidget, + onTap: e.onTap, + )) + .toList() ?? + [ + 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); + }, + ), + ), + ); + }, ), - 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(); - } - }, - ), - ], + 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( + color: chatThemeData.colorTheme.accentRed, + ), + ); + if (res == true) { + await channel.delete(); + } + }, + ), + ], child: Container( color: chatThemeData.colorTheme.whiteSnow, child: widget.channelPreviewBuilder?.call(context, channel) ?? @@ -650,3 +661,15 @@ class _ChannelListViewState extends State { ); } } + +class SwipeAction { + Color? color; + Widget iconWidget; + VoidCallback? onTap; + + SwipeAction({ + this.color, + required this.iconWidget, + this.onTap, + }); +} From 56e7d45cb8e4f590316fb8f23f0274cca92913cc Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Mon, 31 May 2021 14:28:49 +0530 Subject: [PATCH 5/7] analysis fixes --- .../lib/src/channel_list_view.dart | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 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 1478c745..049a51af 100644 --- a/packages/stream_chat_flutter/lib/src/channel_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/channel_list_view.dart @@ -662,14 +662,21 @@ class _ChannelListViewState extends State { } } +/// Class for slidable action class SwipeAction { - Color? color; - Widget iconWidget; - VoidCallback? onTap; - + /// Constructor for creating [SwipeAction] SwipeAction({ this.color, required this.iconWidget, this.onTap, }); + + /// Background color of action + Color? color; + + /// Widget to display as icon + Widget iconWidget; + + /// Callback when icon is tapped + VoidCallback? onTap; } From 5ed6932ef20df419a3593322ca55e928eb288ecd Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Mon, 31 May 2021 14:29:11 +0530 Subject: [PATCH 6/7] analysis fixes --- packages/stream_chat_flutter/lib/src/channel_list_view.dart | 1 + 1 file changed, 1 insertion(+) 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 049a51af..8a5bc78d 100644 --- a/packages/stream_chat_flutter/lib/src/channel_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/channel_list_view.dart @@ -529,6 +529,7 @@ class _ChannelListViewState extends State { title: 'Delete Conversation', okText: 'DELETE', question: + // ignore: lines_longer_than_80_chars 'Are you sure you want to delete this conversation?', cancelText: 'CANCEL', icon: StreamSvgIcon.delete( From 23d992740f23e54f7144c9fe8d4a5e1c9b2a5581 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Tue, 1 Jun 2021 17:46:12 +0530 Subject: [PATCH 7/7] Changed callback type --- .../lib/src/channel_list_view.dart | 91 +++++++++++-------- 1 file changed, 51 insertions(+), 40 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 8a5bc78d..911e0a41 100644 --- a/packages/stream_chat_flutter/lib/src/channel_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/channel_list_view.dart @@ -12,6 +12,9 @@ import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart'; /// Callback called when tapping on a channel typedef ChannelTapCallback = void Function(Channel, Widget?); +/// Callback called when tapping on a channel +typedef ChannelInfoCallback = void Function(Channel); + /// Builder used to create a custom [ChannelPreview] from a [Channel] typedef ChannelPreviewBuilder = Widget Function(BuildContext, Channel); @@ -162,10 +165,10 @@ class ChannelListView extends StatefulWidget { final WidgetBuilder? emptyBuilder; /// Callback used when the more details slidable option is pressed - final VoidCallback? onMoreDetailsPressed; + final ChannelInfoCallback? onMoreDetailsPressed; /// Callback used when the delete slidable option is pressed - final VoidCallback? onDeletePressed; + final ChannelInfoCallback? onDeletePressed; /// List of actions for slidable final List? swipeActions; @@ -481,34 +484,39 @@ class _ChannelListViewState extends State { ?.map((e) => IconSlideAction( color: e.color, iconWidget: e.iconWidget, - onTap: e.onTap, + onTap: () { + e.onTap?.call(channel); + }, )) .toList() ?? [ 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), + onTap: widget.onMoreDetailsPressed != null + ? () { + widget.onMoreDetailsPressed!(channel); + } + : () { + 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); - }, + context: context, + builder: (context) => StreamChannel( + channel: channel, + child: ChannelBottomSheet( + onViewInfoTap: () { + widget.onViewInfoTap?.call(channel); + }, + ), ), - ), - ); - }, + ); + }, ), if ([ 'admin', @@ -522,24 +530,27 @@ class _ChannelListViewState extends State { iconWidget: StreamSvgIcon.delete( color: chatThemeData.colorTheme.accentRed, ), - onTap: widget.onDeletePressed ?? - () async { - final res = await showConfirmationDialog( - context, - title: 'Delete Conversation', - okText: 'DELETE', - question: - // ignore: lines_longer_than_80_chars - 'Are you sure you want to delete this conversation?', - cancelText: 'CANCEL', - icon: StreamSvgIcon.delete( - color: chatThemeData.colorTheme.accentRed, - ), - ); - if (res == true) { - await channel.delete(); + onTap: widget.onDeletePressed != null + ? () { + widget.onDeletePressed!(channel); } - }, + : () async { + final res = await showConfirmationDialog( + context, + title: 'Delete Conversation', + okText: 'DELETE', + question: + // ignore: lines_longer_than_80_chars + '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( @@ -679,5 +690,5 @@ class SwipeAction { Widget iconWidget; /// Callback when icon is tapped - VoidCallback? onTap; + ChannelInfoCallback? onTap; }