letsar / flutter_slidable

A Flutter implementation of slidable list item with directional slide actions.
MIT License
2.72k stars 589 forks source link

Cannot dismiss tile on tap #326

Open nicolasvahidzein opened 2 years ago

nicolasvahidzein commented 2 years ago

It seems many people are running into this issue that is hard to figure out:

Getting the slideaction to dismiss programmatically:

https://github.com/letsar/flutter_slidable/issues/31#issuecomment-880840889

this commenet does not work, can @letsar you please guide us by posting the proper procedure here or update the docs to show us how to accomplish this please?

Thank you so much.

nicolasvahidzein commented 2 years ago

Inside my SlidableAction onPressed callback i have this code but the controller is returned null, how is this possible inside the widget. It's strange to me?

final controller = Slidable.of(context);

if (controller == null) {
    print('slidable controller is INDEED null');
}
nicolasvahidzein commented 2 years ago

I found the issue, we need to pass the fresh context as mentionned in some of the issues on this repo, see "contexto" below.

However this uses the rightmost icon as the one that will expand and be used during the dismiss animation and that is not what we want.

How can we address that?

onPressed: (contexto) {

_swipedAction('delete');

print('this should close');

final controller = Slidable.of(contexto);

if (controller == null) {

print('slidable controller is INDEED null');

} else {

print('slidable controller is NOT null');

controller.dismiss(
    ResizeRequest(
        const Duration(milliseconds: 300),
        () {
            print('Dismiss from Button');
        }
    ),
);

}

},
nicolasvahidzein commented 2 years ago

@HammadBukhari

nicolasvahidzein commented 2 years ago

@hammadbukhari I need your help please.

nicolasvahidzein commented 2 years ago

I uploaded a demo video of what is happening:

https://youtube.com/shorts/XIdIaTwrtt4?feature=share

When we press on the left item contained in an endActionPane and trigger a programmatic onDismiss action, it is the blue (right most icon) that is expanded when the onDismiss action is triggered and not the icon (the red delete one) that was tapped.

How can we fix this please?

cliftonscott commented 2 years ago

@nicolasvahidzein this is what I did to dismiss a list item on tap.

endActionPane: ActionPane(
  motion: const BehindMotion(),

  dismissible: DismissiblePane(onDismissed: () {}),

  children: [
    SlidableAction(
      autoClose: false,
      onPressed: (context) {
        final controller = Slidable.of(context);
        controller?.dismiss(
          ResizeRequest(
              const Duration(milliseconds: 300),
              () => comments
                  ?.remove(comments[index])),
          duration:
              const Duration(milliseconds: 300),
        );
      },
      backgroundColor: Colors.red,
      foregroundColor: Colors.white,
      icon: Icons.delete,
      label: 'Delete',
    ),
  ]
)
nicolasvahidzein commented 2 years ago

@cliftonscott thank you so much Clifton, i will try this tomorrow and revert back. Much appreciated.

caseyryan commented 2 years ago

doesn't work for me

Zechst commented 2 years ago

doesn't work for me too :(

bakatsuyuki commented 2 years ago

I have the same issue :(

fullflash commented 1 year ago

does not work i currently SlidableController dismiss method does not anything.

nicolasvahidzein commented 1 year ago

It would be nice if the maintainer could look into this after all this time.

naddamuhamed commented 1 year ago

it's not working. nothing is happening! the print inside the resize request doesn't show so it doesn't even get into the ondimissed() function and it doesn't remove anything or show any dismissal animation i have been on this issue for 3 days now.

nicolasvahidzein commented 1 year ago

Is the maintainer still working on this issue? We are all still waiting for this feature. Anyone reading this?

Zechst commented 1 year ago

I guess not. It probably be better if we fork the repo and maintain it until he comes back

Zechst commented 1 year ago

I guess not. It probably be better if we fork the repo and maintain it until he comes back

liam-duan commented 1 year ago

autoClose needs to be false. This code works for me

SlidableAction(
                      autoClose: false,
                      borderRadius: BorderRadius.circular(12),
                      onPressed: (context) {
                        final controller = Slidable.of(context);
                        controller?.dismiss(
                          ResizeRequest(
                              const Duration(milliseconds: 300), () => {}),
                          duration: const Duration(milliseconds: 300),
                        );
                      },
                      backgroundColor: const Color(0xFFFE4A49),
                      foregroundColor: Colors.white,
                      icon: Icons.delete,
                      label: 'Delete',
                    ),
nomtats commented 7 months ago

I bumped into a similar issue, autoClose: false worked for me.