flutter_slidable
flutter_slidable copied to clipboard
Swipe to perform one action
Hi
I want to know if it's possible to perform only one action automatically without having to tap on icon ?
Like dismissible widget but without the remove effect ?
I want to allow user to go to edit page with a swipe to right. The problem with the dismissible widget is the effect that remove the item.
Thanks
You can use Slidable.builder to check the animation and trigger an action (f.e when the animation is completed)
Slidable.builder(
actionPane: const SlidableStrechActionPane(),
actionExtentRatio: .6,
actionDelegate: SlideActionBuilderDelegate(
builder: (context, index, animation, step) {
// print('Current Animation: ${animation}');
if (animation!.isCompleted) {
final controller = Slidable.of(context);
controller!.close();
// perform an action here
}
return Icon(
Icons.check,
size: 40 * animation.value,
color: animation.value > 0.5 ? kcPrimary500 : Colors.grey,
).alignment(Alignment.centerRight).padding(right: 16);
},
actionCount: 1,
),
child: ...
);
Slidable.builder is no longer in version 1.1.0 @avatarnguyen @letsar What is the current alternative for the above mentioned flow? Thank you.
Any news about that? I am pretty sure it is a very interesting feature.
@Hydro8 @yassinsameh @JeanPSF Hire is answer: https://github.com/letsar/flutter_slidable/issues/318#issuecomment-1068788262
Any new update on this?
I didn't find any solution! how to archive this in the latest version of flutter_slidable
here is a solution work for me (flutter_slidable version 3.0.0) 80% swipe right to left (0.8 threhold) to popup ask for delete => if yes, delete and dismiss, otherwise keep it and close.
Slidable(
key: ValueKey(Random().nextInt(10000)), // key for use confirmDismiss, random key is important for multiple data
endActionPane: ActionPane(
dismissible: DismissiblePane(
dismissThreshold: 0.8,
closeOnCancel: true, // auto close when user cancel popup
confirmDismiss: () async {
return await controller.askUserForDelete(); // return Future<bool> true false
}, onDismissed: () {
// if user grant permission to delete, onDismissed will be called => you can do your logic delete here
// otherwise closeOnCancel will trigger and it will automatically close
},
),
motion: const DrawerMotion(),
children: [
SlidableAction(
autoClose: false, // important if you want to programmatically close or dismiss
icon: Icons.delete,
label: "Delete",
backgroundColor: Colors.red,
onPressed: (context) async {
final result = await controller.askUserForDelete();
final slideController = Slidable.of(context);
if (result == true) { // user grant permission to delete => dismiss
slideController?.dismiss(
ResizeRequest(const Duration(milliseconds: 300), () => {
// you can do your logic here
}),
duration: const Duration(milliseconds: 300),
);
} else { // not allow to delete => close
slideController?.close(duration: const Duration(milliseconds: 300), curve: Curves.decelerate);
}
}
)
],
),
child: ....
);