Using Dismissible widgets for swipe actions can affect your app's frame rate if you have many items in a list. Each swipe gesture triggers animations and state changes, which require CPU and GPU work. On mid-range devices, smooth 60fps is achievable if you keep the list size reasonable and avoid heavy rebuilds during swipe. Memory usage is generally low, but excessive use of complex child widgets inside Dismissible can increase memory and battery drain.
Dismissible for swipe actions in Flutter - Build, Publish & Deploy
- Use lightweight child widgets inside
Dismissibleto reduce rendering cost. - Limit the number of
Dismissiblewidgets visible on screen by using lazy loading withListView.builder. - Cache data and avoid rebuilding the entire list on each swipe.
- Use
keyproperties properly to help Flutter efficiently identify widgets. - Keep swipe animations simple and avoid complex custom animations.
The Dismissible widget is part of Flutter's core framework, so it does not add extra size to your app bundle. However, if you add many custom swipe actions or animations, those can increase your app size slightly. Startup time is not affected by using Dismissible unless you preload large data sets or images for the list items.
On both iOS and Android, Dismissible provides consistent swipe-to-dismiss behavior. However, platform conventions differ:
- iOS: Swipe actions often reveal buttons like "Delete" or "Archive". The swipe gesture is usually from right to left.
- Android: Swipe to dismiss is common, but Material Design encourages using snackbars for undo actions after dismissal.
Flutter's Dismissible widget works the same on both platforms, but you should adapt UI feedback and undo options to platform guidelines.
- Apple App Store: Ensure swipe actions do not cause accidental data loss. Provide undo options or confirmation dialogs if dismissing important content.
- Google Play Store: Follow Material Design guidelines for swipe gestures and feedback. Avoid confusing or inconsistent swipe behaviors.
- Both stores require accessible UI: make sure swipe actions are accessible via keyboard and screen readers.
If your app takes 5 seconds to load a screen with Dismissible widgets, likely issues include:
- Loading too many list items at once without lazy loading.
- Heavy widget trees inside each
Dismissiblecausing slow build times. - Expensive operations (like network calls or image decoding) happening synchronously during build.
- Improper use of keys causing Flutter to rebuild widgets unnecessarily.
To fix, use ListView.builder for lazy loading, simplify child widgets, and move heavy work outside the build method.
Practice
Dismissible widget in Flutter?Solution
Step 1: Understand the widget's function
TheDismissiblewidget is designed to let users swipe list items to remove them.Step 2: Compare options with the widget's purpose
Only To allow users to swipe and remove items from a list describes swiping to remove items, which matchesDismissible's role.Final Answer:
To allow users to swipe and remove items from a list -> Option CQuick Check:
Dismissible = swipe to remove [OK]
- Confusing Dismissible with buttons or animations
- Thinking it manages image layouts
- Assuming it changes text colors
Dismissible widget?Solution
Step 1: Review key types for Dismissible
Flutter requires a unique key for eachDismissible.Key,UniqueKey(), andValueKey()are all valid ways to create unique keys.Step 2: Confirm all options are valid
Each option shows a valid key assignment method, so all are correct.Final Answer:
All of the above -> Option DQuick Check:
Any unique key type works [OK]
- Using non-unique keys like constant strings for all items
- Omitting the key parameter
- Using keys that are not unique per item
Dismissible(
key: Key('item1'),
onDismissed: (direction) {
items.removeAt(0);
},
child: ListTile(title: Text('Item 1')),
)Solution
Step 1: Understand onDismissed callback
TheonDismissedcallback removes the first item from theitemslist when swiped.Step 2: Analyze the effect of removing item at index 0
Removing at index 0 deletes the first item, so the list updates accordingly.Final Answer:
The first item is removed from the list -> Option AQuick Check:
onDismissed removes item at index 0 [OK]
- Assuming key error prevents removal
- Forgetting to update the list state
- Thinking swipe duplicates items
Dismissible usage?Dismissible(
key: Key('item'),
onDismissed: (direction) {
items.removeAt(index);
},
child: ListTile(title: Text('Item')),
)Solution
Step 1: Check the key uniqueness
The key isKey('item')which is constant and not unique per item, causing issues in lists.Step 2: Verify other parts
TheonDismissedcallback exists, child is a ListTile, andindexis assumed defined, so no issues there.Final Answer:
The key is not unique for each item -> Option AQuick Check:
Keys must be unique per Dismissible [OK]
- Using same key for all items
- Ignoring key importance in lists
- Assuming onDismissed is optional
Dismissible item to the left. Which code snippet correctly implements this?Solution
Step 1: Understand background property
Thebackgroundexpects a widget behind the item during swipe, usually a colored container with an icon.Step 2: Check each option's correctness
The snippet withContainer(color: Colors.red, child: Icon(Icons.delete, color: Colors.white))provides a red background with a visible white trash icon. Others lack a container, the icon, or use colors that do not produce a red background with a visible trash icon.Final Answer:
background: Container(color: Colors.red, child: Icon(Icons.delete, color: Colors.white)) -> Option BQuick Check:
Red container + white icon = correct swipe background [OK]
- Using icon alone without container
- Wrong colors making icon invisible
- Missing icon in background
Ready to prove it?
Pass the test and this pattern moves unknown
