Limiting Dissmisble widget triggering

216 Views Asked by At

I use the Dissmisble widget to remove an item from a list. I would like to be able to limit the trigger zone (after which the swipe begins) in the child widget.

I.e. we have a widget in the list, which is wrapped in Dissmisble, if you start swipe to the right in any zone of this widget it will start dismissmisble process. I would like to limit this zone for example to the right side of child widget.

It seems that this behavior will be similar to what it would be if there was a DissmissDirection.centerToEnd.

Whether it is possible to make it?

I tried to change the constant values in the dissmisble widget itself, but did not get the behavior I was looking for.

1

There are 1 best solutions below

1
On

you can set dismissThreshold property. https://api.flutter.dev/flutter/widgets/Dismissible/dismissThresholds.html

// this will only allow slide to left. Right slide will disabled.
direction: DismissDirection.endToStart,

// item will dismissed after slide 90%
// you can set between 0.0 - 1.0
// change direction as you need
dismissThresholds: {DismissDirection.endToStart: 0.9}, 

example implementaiton:

Dismissible(
  key: ValueKey<int>(items[index]),
  direction: DismissDirection.endToStart,// this will only allow slide to left.
  dismissThresholds: {DismissDirection.endToStart: 0.9}, // item will dismissed after slide 90%
  onDismissed: (DismissDirection direction) {
    setState(() {
      items.removeAt(index);
    });
  },
  child: ListTile(
    title: Text(
      'Item ${items[index]}',
    ),
  ),
);