user6274128
user6274128

Reputation:

ListView animation when item is deleted using Dismissible

I'm using Dismissible to dismiss the items, but when an item is dismissed I get default boring animation. Is there a way to change that animation like Gmail does?

Example:

enter image description here

My own animation (not smooth)

enter image description here

So, in my animation, you can see slight pause when the item is deleted and next item coming up on the screen taking up old item position.

Upvotes: 1

Views: 1973

Answers (2)

user6274128
user6274128

Reputation:

Thanks to @Rémi Rousselet for his efforts.

Finally I found the reason for that ugly animation. Never use itemExtent when you are planning to use Dismissible. I was mad, I used it.

Upvotes: 0

Rémi Rousselet
Rémi Rousselet

Reputation: 277037

That's the default animation of Dismissible.

List<String> content;

ListView.builder(
  itemCount: content.length,
  itemBuilder: (context, index) {
    return Dismissible(
      key: ValueKey(content[index]),
      onDismissed: (_) {
        setState(() {
          content = List.from(content)..removeAt(index);
        });
      },
      background: Container(color: Colors.green),
      child: ListTile(
        title: Text(content[index]),
      ),
    );
  },
)

Upvotes: 1

Related Questions