'how to make tap to open slidable using flutter_slidable package?

to achieve this

enter image description here

currently I use this code below

          Slidable(
              child: ProductListItem(product: product),
              endActionPane: ActionPane(
                motion: const StretchMotion(),
                children: [
                  SlidableAction(
                    onPressed: (context) {
                      //
                    },
                    backgroundColor: Colors.orange,
                    foregroundColor: Colors.white,
                    icon: Icons.edit,
                    label: "edit".tr(),
                  ),
                  SlidableAction(
                    onPressed: (context) {
                      //
                    },
                    backgroundColor: Colors.red,
                    foregroundColor: Colors.white,
                    icon: Icons.delete,
                    label: "delete".tr(),
                  ),
                ],
              ),
            ),

I need to swipe in the right side to open that endPaneActions.

what I want is ....

if I tap that list item, then it will programmatically open that endPaneActions. how to do that?

from the tutorial on Youtube in here , it seems I can use the code below

final slidable = Slidable.of(context);
final isClosed = slidable.renderingMode == SlidableRenderingMode.none;

if (isClosed) {
   slidable.open();
}

but it seems that code is obsolete, I can't find .renderingMode method on version 1.2.0

what is the latest version to programmatically open 'end actions pane' ?



Solution 1:[1]

finally I can make tap to open slidable programmatically on version 1.2.0. I got a clue from austin's answer on Github

           Slidable(
              child: LayoutBuilder( // <---- add LayoutBuilder
                builder: (contextFromLayoutBuilder, constraints) {
                  return GestureDetector( // <--- add Gesture Detector
                    child: YourListItem(), // <--- your list item in here
                    onTap: () {

                      final slidable = Slidable.of(contextFromLayoutBuilder);
                      slidable?.openEndActionPane(
                        duration: const Duration(milliseconds: 500),
                        curve: Curves.decelerate,
                      );

                    },
                  );
                },
              ),
              endActionPane: ActionPane( // <--- I use endActionPane in here
                motion: const StretchMotion(),
                children: [],
              ),
         )

as you can see, I add LayoutBuilder and GestureDetector inside the Slidable widget. LayoutBuilder is used to get the 'latest' context inside the Slidable widget, so the slidable value will not be null.

NOTE: I use endActionPane here, so I use openEndActionPane method. if you use startActionPane, then you should use openStartActionPane method instead

Solution 2:[2]

The behavior you're seeing can be reproduced much more simply:

await Task.CompletedTask.ContinueWith(task =>
    {
    }, TaskContinuationOptions.NotOnRanToCompletion);

TaskContinuationOptions.NotOnRanToCompletion instructs the ContinueWith method to not execute the callback if the task completes successfully, and instead return a cancelled task.

You would use that option if you have a continuation that you specifically expect to run when an error occurs. For example:

await Task.FromException(new Exception()).ContinueWith(task =>
    {
        Console.WriteLine("Task did not execute to completion");
    }, TaskContinuationOptions.NotOnRanToCompletion);

Since it looks like you expect this.provider.UpdateAsync(record) might succeed, that's probably not the option you want to use.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2