1. Swipe-to-delete with Dismissible
Dismissible wraps a row, draws a background while it is dragged, and calls onDismissed once the row has been swiped off. Two rules prevent most bugs: give each row a key from your data (not the index), and remove the item from your list inside onDismissed, or Flutter throws because a dismissed widget is still in the tree.
Deleting on a single gesture is easy to do by accident, so pair it with an undo SnackBar rather than a confirmation dialog.
import 'package:flutter/material.dart';
class Message {
const Message(this.id, this.title);
final String id;
final String title;
}
class InboxList extends StatefulWidget {
const InboxList({super.key});
@override
State<InboxList> createState() => _InboxListState();
}
class _InboxListState extends State<InboxList> {
final List<Message> _messages = [
const Message('1', 'Pricing page feedback'),
const Message('2', 'Build 482 passed'),
const Message('3', 'Can we ship Friday?'),
];
void _delete(Message message) {
final index = _messages.indexOf(message);
setState(() => _messages.removeAt(index));
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(
SnackBar(
content: Text('Deleted "${message.title}"'),
action: SnackBarAction(
label: 'Undo',
onPressed: () => setState(() {
final at = index > _messages.length ? _messages.length : index;
_messages.insert(at, message);
}),
),
),
);
}
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: _messages.length,
itemBuilder: (context, index) {
final message = _messages[index];
return Dismissible(
key: ValueKey(message.id),
direction: DismissDirection.endToStart,
background: Container(
alignment: Alignment.centerRight,
padding: const EdgeInsets.symmetric(horizontal: 24),
color: Colors.red.shade600,
child: const Icon(Icons.delete_outline, color: Colors.white),
),
onDismissed: (_) => _delete(message),
child: ListTile(
title: Text(message.title),
// A visible alternative for people who can't or don't swipe
trailing: IconButton(
tooltip: 'Delete',
icon: const Icon(Icons.delete_outline),
onPressed: () => _delete(message),
),
),
);
},
);
}
}2. Ask before dismissing (optional)
confirmDismiss runs when the swipe completes and before the row is removed. Return false to snap the row back. Use it when one direction should do something other than delete, such as archiving, or for the rare action that can't be undone.
Dismissible(
key: ValueKey(message.id),
confirmDismiss: (direction) async {
if (direction == DismissDirection.startToEnd) {
archive(message);
return false; // keep the row, just mark it archived
}
return true;
},
onDismissed: (_) => _delete(message),
child: ListTile(title: Text(message.title)),
)3. Revealing several actions behind a row
Dismissible is built to remove a row. Mail-style rows that slide partway open to show Archive and Delete buttons need a different widget: a horizontal drag that stops at a detent, a spring to settle open or closed, a way to close when another row opens, and a non-gesture way to reach the actions.
You can build that with a GestureDetector, a Stack and an unbounded AnimationController running a SpringSimulation (see the spring basics guide). It's a good exercise; it is also roughly 200 lines once keyboard, semantics and edge cases are handled.
4. Kipluo SwipeAction
Kipluo's Swipe Action is a paid widget. The row opens and closes on a spring that carries your fling velocity, a long swipe past fullSwipeThreshold runs the first action directly with a tick sound as you cross it, Escape closes an open row, and a "Row actions" menu button gives the same actions without any gesture.
Install it with npx kipluo add swipe-action --flutter, which copies the Dart source into lib/kipluo/.
SwipeAction(
semanticLabel: message.title,
actions: [
SwipeActionItem(
label: 'Archive',
icon: Icons.archive_outlined,
onTrigger: () => archive(message),
),
SwipeActionItem(
label: 'Delete',
icon: Icons.delete_outline,
destructive: true,
onTrigger: () => _delete(message),
),
],
child: ListTile(title: Text(message.title)),
)Accessibility checklist
Tick each one off as you check your build. Your ticks stay in this browser.
0 of 4 checked
Build it yourself or install it
Build it yourself when
Swipe-to-delete with undo. Dismissible does it well in about 40 lines.
Install Kipluo when
You need multiple revealed actions, spring settle, full-swipe, sound and a built-in menu fallback, matching your React list.