I have ListView with onDismissed and onConfirmDismiss.

I have a requirement to disable or not to delete specific item in list.

How can I disable swipe for specific item?


Solution 1: Masum Billah Sanjid

Look i disabled some specific item with condition try like this.

List<int> items = List<int>.generate(100, (int index) => index);

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: items.length,
      padding: const EdgeInsets.symmetric(vertical: 16),
      itemBuilder: (BuildContext context, int index) {
        if(index%2==0){
          return  ListTile(
            title: Text(
              'Item ${items[index]}',
            ),
          );
        }

        return  Dismissible(
          background: Container(
            color: Colors.green,
          ),
          key: ValueKey<int>(items[index]),
          onDismissed: (DismissDirection direction) {
            setState(() {
              items.removeAt(index);
            });
          },
          child: ListTile(
            title: Text(
              'Item ${items[index]}',
            ),
          ),
        );
      },
    );
  }


Solution 2: Alex Aung

I use condition in direction.

direction: favourites[index].isDefault
          ? DismissDirection.none
          : DismissDirection.horizontal,