Contents

Flutter and Android development with Kotlin

Widget cost estimator
Coding With Dhrumil
Tools
All articles→

Flutter Slidable Widget: Swipe Actions Done Right

Build swipe-to-delete and reveal actions in Flutter with the Slidable widget: setup, action panes, dismiss thresholds, keys, and performance tips that hold up.

A list item being swiped to reveal action buttons on a mobile app
A list item being swiped to reveal action buttons on a mobile app · Foto: geralt / Pixabay

Swipe actions are one of those features users expect without asking for it: swipe a row to archive it, flag it, or delete it. In Flutter the shortest path to that behaviour is the Slidable widget, which wraps any list row and reveals a pane of buttons as the user drags horizontally. It is small, composable, and easy to get wrong in subtle ways once real data and long lists are involved.

This article walks through a working setup, the parts that actually matter (action panes, dismiss thresholds, stable keys), and the edge cases that bite in production. The examples assume a list of items with unique ids, because almost every bug people hit with Slidable traces back to missing or reused keys.

Key points

  • Key every Slidable by item id, never by list index.
  • Keep extentRatio between 0.2 and 0.4 and limit actions to two per side.
  • Confirm destructive swipes and always provide undo.
  • Offer a non-gesture path for screen reader and keyboard users.

Add the dependency and build a first swipe row

Start by adding the package to pubspec.yaml and running a pub get. Keep the constraint loose enough to accept patch fixes but pinned enough that a breaking minor release does not surprise you mid-sprint; something like a caret constraint on the current major version is the usual choice. After that, a Slidable needs only two things to render: a key and a list of action panes.

The minimal shape is a Slidable wrapping your row content, with one endActionPane containing a SlidableAction. The action pane takes an extentRatio, which is the fraction of the row width the pane occupies when open. Values between 0.2 and 0.35 feel right for one or two buttons; going above 0.4 makes the row feel like it is falling apart.

Give the Slidable a ValueKey built from the item id, not the index. When a list reorders or an item is removed, index-based keys cause the open pane to jump to a different row, which looks like a rendering bug but is really a widget identity problem. This is the same identity discipline that keeps any stateful list healthy.

  • Slidable(key: ValueKey(item.id), endActionPane: ...)
  • extentRatio: 0.25 for a single delete action
  • Wrap the row child in a ListTile or custom Row
  • Set closeOnScroll: true so open panes close as the user scrolls

Action panes, buttons, and the dismiss flow

SlidableAction gives you an icon, a label, a background colour, and an onPressed callback. Keep labels to one or two words and colours to your theme's error and secondary containers; a row of five saturated buttons reads as noise. Two actions per side is a comfortable ceiling on phones, and on narrow screens even two labels can truncate, so test with a long localisation string.

For destructive actions, wrap the pane in a Dismissible-style flow rather than firing the delete immediately. The package supports a confirmDismiss callback on the dismissible pane, which lets you show a dialog and return a boolean. Fire the actual removal only after the future resolves true, and animate the list with AnimatedList or an implicit animation so the row does not vanish abruptly.

Do the removal in your state layer first and let the UI rebuild from that state. If you delete optimistically and the write fails, you need a path to restore the row, which is far easier when the list is derived from a store than when widgets mutate themselves.

Keys, controllers, and keeping panes in sync

Each Slidable owns a SlidableController if you need programmatic control, for example closing all open panes when the user taps elsewhere. Creating a controller per row is fine, but creating one inside build without disposing it leaks listeners. Store controllers in state, or use the group concept the package offers when only one row should stay open at a time.

The one-open-pane rule is worth implementing deliberately. Users drag a row, scroll away, come back, and find three panes open. A SlidableGroup or a simple listener that closes the previously opened row fixes this with a few lines and noticeably improves how the list feels.

If your rows live inside a custom scroll view with pinned headers or nested scrollables, check that the horizontal drag gesture does not fight the vertical one. Slidable handles the common case well, but a horizontally scrolling child inside the row will steal the gesture and leave the pane stuck half-open.

  • Dispose any SlidableController you create
  • Use a group or listener to enforce one open pane
  • Avoid horizontal scrollables inside a swipe row
  • Reuse the row widget across lists instead of copy-pasting

Performance in long lists

Slidable adds a gesture detector and an animation controller per row, which is cheap but not free. In a list of a few hundred items with ListView.builder, you will not notice it. In lists that rebuild often, the cost shows up as jank during fast flings, mostly because each rebuild reconstructs action panes and their icons.

Keep the row subtree const where possible and hoist callbacks so they are not recreated on every build. If the list is heavy, consider whether the swipe action is needed on every row or only on rows the user owns. Splitting the list into sections with different row types keeps the gesture surface smaller.

For sizing guidance on how many rows to build and cache, the reasoning in how to size a RecyclerView adapter for smooth lists translates well to Flutter's builder delegates. And if you are counting widgets per screen to find rebuild hotspots, how many widgets a typical Flutter screen really uses gives useful baselines.

0.20380.30210.40120.5060.603
Accidental deletes per 1,000 swipes by dismiss threshold (deletes)

Testing and accessibility

Widget tests for swipe rows are straightforward with WidgetTester.drag: drag the row by a negative dx roughly equal to the pane extent, pump, and expect the action label to be findable. Test the confirm dialog path separately, including the cancel case, because that is where regressions hide after a refactor.

Accessibility matters more here than it seems. A swipe gesture is invisible to screen reader users, so provide an alternative: a long-press menu, a trailing overflow button, or Semantics custom actions on the row. Make sure the action buttons have labels, not just icons, and that the delete action announces its consequence.

Also check text scaling at 1.3x and 2.0x. Action labels that fit at default size will overflow at larger scales, and an overflowing button inside a fixed-extent pane is a guaranteed visual defect on budget devices.

  • Drag tests with a dx matching the pane extent
  • Test confirm and cancel paths separately
  • Expose swipe actions via Semantics or an overflow menu
  • Verify layout at 1.3x and 2.0x text scale
Choosing pane settings for common swipe-row use cases
Use caseextentRatioActions per sideDismiss?Notes
Archive email row0.251NoSingle icon plus label, secondary container colour
Task list item0.352Yes, with confirmDelete plus snooze, undo SnackBar on success
Chat conversation0.21NoMute action only, close on scroll
File manager entry0.42-3Yes, with confirmWidest pane, test at 1.3x text scale
Settings list row0.251NoOften better replaced by an overflow menu

Common mistakes worth avoiding

The most frequent mistake is calling setState on the parent list from inside onPressed while the pane is still animating closed. This rebuilds the row mid-animation and can leave the pane visible on a row that no longer exists. Close first, then mutate, or mutate and let the animation finish on a removed widget.

The second is ignoring the dismiss threshold. Users expect a firm swipe to trigger the action and a light swipe to snap back. Tune the threshold so accidental deletes are rare, and always offer undo via a SnackBar for destructive actions, since a confirmation dialog on every delete becomes tiresome in bulk workflows.

Finally, do not stack Slidable inside another Slidable. Nested horizontal gestures are ambiguous and the inner one usually wins unpredictably. If you need two directions, use startActionPane and endActionPane on the same widget.

Dhrumil Patel

Editor and Flutter contributor. Writes practical Flutter tutorials focused on widgets, layout and animation. Enjoys breaking large UI problems into small, testable pieces and explaining them clearly to beginners.

Flutter Screen Widget and Cost Estimator

Related articles

Cookie preferences

Required for the site to function, including remembering your cookie choice. Always on.

Not used on this site.

Not used on this site.