feat: Added list of actions to channel_list_view.dart

This commit is contained in:
Deven Joshi
2021-05-31 11:30:51 +05:30
parent 765ca60343
commit ceaf30e545
@@ -80,6 +80,7 @@ class ChannelListView extends StatefulWidget {
this.listBuilder, this.listBuilder,
this.onMoreDetailsPressed, this.onMoreDetailsPressed,
this.onDeletePressed, this.onDeletePressed,
this.swipeActions,
}) : super(key: key); }) : super(key: key);
/// If true a default swipe to action behaviour will be added to this widget /// 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 /// Callback used when the delete slidable option is pressed
final VoidCallback? onDeletePressed; final VoidCallback? onDeletePressed;
/// Actions shown when list tile is swiped
final List<IconSlideAction>? swipeActions;
@override @override
_ChannelListViewState createState() => _ChannelListViewState(); _ChannelListViewState createState() => _ChannelListViewState();
} }
@@ -473,61 +477,64 @@ class _ChannelListViewState extends State<ChannelListView> {
enabled: widget.swipeToAction, enabled: widget.swipeToAction,
actionPane: const SlidableBehindActionPane(), actionPane: const SlidableBehindActionPane(),
actionExtentRatio: 0.12, actionExtentRatio: 0.12,
secondaryActions: <Widget>[ secondaryActions: widget.swipeActions ??
IconSlideAction( <Widget>[
color: backgroundColor, IconSlideAction(
icon: Icons.more_horiz, color: backgroundColor,
onTap: widget.onMoreDetailsPressed ?? () { icon: Icons.more_horiz,
showModalBottomSheet( onTap: widget.onMoreDetailsPressed ??
clipBehavior: Clip.hardEdge, () {
shape: const RoundedRectangleBorder( showModalBottomSheet(
borderRadius: BorderRadius.only( clipBehavior: Clip.hardEdge,
topLeft: Radius.circular(32), shape: const RoundedRectangleBorder(
topRight: Radius.circular(32), borderRadius: BorderRadius.only(
), topLeft: Radius.circular(32),
), topRight: Radius.circular(32),
context: context, ),
builder: (context) => StreamChannel( ),
channel: channel, context: context,
child: ChannelBottomSheet( builder: (context) => StreamChannel(
onViewInfoTap: () { channel: channel,
widget.onViewInfoTap?.call(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 { if ([
final res = await showConfirmationDialog( 'admin',
context, 'owner',
title: 'Delete Conversation', ].contains(channel.state!.members
okText: 'DELETE', .firstWhereOrNull(
question: (m) => m.userId == channel.client.state.user?.id)
'Are you sure you want to delete this conversation?', ?.role))
cancelText: 'CANCEL', IconSlideAction(
icon: StreamSvgIcon.delete( color: backgroundColor,
iconWidget: StreamSvgIcon.delete(
color: chatThemeData.colorTheme.accentRed, color: chatThemeData.colorTheme.accentRed,
), ),
); onTap: widget.onDeletePressed ??
if (res == true) { () async {
await channel.delete(); 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( child: Container(
color: chatThemeData.colorTheme.whiteSnow, color: chatThemeData.colorTheme.whiteSnow,
child: widget.channelPreviewBuilder?.call(context, channel) ?? child: widget.channelPreviewBuilder?.call(context, channel) ??