added swipe actions list
This commit is contained in:
@@ -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;
|
||||||
|
|
||||||
|
/// List of actions for slidable
|
||||||
|
final List<SwipeAction>? swipeActions;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_ChannelListViewState createState() => _ChannelListViewState();
|
_ChannelListViewState createState() => _ChannelListViewState();
|
||||||
}
|
}
|
||||||
@@ -473,63 +477,70 @@ 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(
|
?.map((e) => IconSlideAction(
|
||||||
color: backgroundColor,
|
color: e.color,
|
||||||
icon: Icons.more_horiz,
|
iconWidget: e.iconWidget,
|
||||||
onTap: widget.onMoreDetailsPressed ??
|
onTap: e.onTap,
|
||||||
() {
|
))
|
||||||
showModalBottomSheet(
|
.toList() ??
|
||||||
clipBehavior: Clip.hardEdge,
|
<Widget>[
|
||||||
shape: const RoundedRectangleBorder(
|
IconSlideAction(
|
||||||
borderRadius: BorderRadius.only(
|
color: backgroundColor,
|
||||||
topLeft: Radius.circular(32),
|
icon: Icons.more_horiz,
|
||||||
topRight: Radius.circular(32),
|
onTap: widget.onMoreDetailsPressed ??
|
||||||
),
|
() {
|
||||||
),
|
showModalBottomSheet(
|
||||||
context: context,
|
clipBehavior: Clip.hardEdge,
|
||||||
builder: (context) => StreamChannel(
|
shape: const RoundedRectangleBorder(
|
||||||
channel: channel,
|
borderRadius: BorderRadius.only(
|
||||||
child: ChannelBottomSheet(
|
topLeft: Radius.circular(32),
|
||||||
onViewInfoTap: () {
|
topRight: Radius.circular(32),
|
||||||
widget.onViewInfoTap?.call(channel);
|
),
|
||||||
},
|
),
|
||||||
),
|
context: context,
|
||||||
),
|
builder: (context) => StreamChannel(
|
||||||
);
|
channel: channel,
|
||||||
},
|
child: ChannelBottomSheet(
|
||||||
),
|
onViewInfoTap: () {
|
||||||
if ([
|
widget.onViewInfoTap?.call(channel);
|
||||||
'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 ??
|
if ([
|
||||||
() async {
|
'admin',
|
||||||
final res = await showConfirmationDialog(
|
'owner',
|
||||||
context,
|
].contains(channel.state!.members
|
||||||
title: 'Delete Conversation',
|
.firstWhereOrNull(
|
||||||
okText: 'DELETE',
|
(m) => m.userId == channel.client.state.user?.id)
|
||||||
question:
|
?.role))
|
||||||
'Are you sure you want to delete this conversation?',
|
IconSlideAction(
|
||||||
cancelText: 'CANCEL',
|
color: backgroundColor,
|
||||||
icon: StreamSvgIcon.delete(
|
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) ??
|
||||||
@@ -650,3 +661,15 @@ class _ChannelListViewState extends State<ChannelListView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SwipeAction {
|
||||||
|
Color? color;
|
||||||
|
Widget iconWidget;
|
||||||
|
VoidCallback? onTap;
|
||||||
|
|
||||||
|
SwipeAction({
|
||||||
|
this.color,
|
||||||
|
required this.iconWidget,
|
||||||
|
this.onTap,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user