flutter_slidable icon indicating copy to clipboard operation
flutter_slidable copied to clipboard

Swipe to perform one action

Open Hydro8 opened this issue 3 years ago • 7 comments

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

Hydro8 avatar Aug 25 '21 07:08 Hydro8

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:  ...
);

avatarnguyen avatar Sep 30 '21 14:09 avatarnguyen

Slidable.builder is no longer in version 1.1.0 @avatarnguyen @letsar What is the current alternative for the above mentioned flow? Thank you.

yassinsameh avatar Nov 21 '21 13:11 yassinsameh

Any news about that? I am pretty sure it is a very interesting feature.

JeanPSF avatar Jul 27 '22 11:07 JeanPSF

@Hydro8 @yassinsameh @JeanPSF Hire is answer: https://github.com/letsar/flutter_slidable/issues/318#issuecomment-1068788262

hlazarpesic avatar Jan 24 '23 21:01 hlazarpesic

Any new update on this?

YagneshVerve avatar Jun 02 '23 12:06 YagneshVerve

I didn't find any solution! how to archive this in the latest version of flutter_slidable

YagneshVerve avatar Jun 02 '23 12:06 YagneshVerve

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: ....
);

pulpcorn avatar Jun 19 '23 18:06 pulpcorn