Challenge - 5 Problems
Dismissible Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when you swipe a Dismissible widget?
Consider a Flutter app with a Dismissible widget wrapping a ListTile. What is the default behavior when the user swipes the item from right to left?
Flutter
Dismissible( key: Key('item1'), child: ListTile(title: Text('Swipe me')), onDismissed: (direction) { print('Item dismissed'); }, )
Attempts:
2 left
💡 Hint
Think about what Dismissible is designed to do when swiped.
✗ Incorrect
The Dismissible widget detects swipe gestures and removes the widget from the tree, calling the onDismissed callback to notify the app.
📝 Syntax
intermediate2:00remaining
Which code correctly implements a Dismissible with a red background on swipe?
You want to show a red background behind the item when swiped. Which code snippet correctly sets this up?
Attempts:
2 left
💡 Hint
The background property expects a widget, not a color directly.
✗ Incorrect
The background property must be a widget, such as a Container with a color. Option D passes a color directly, which is invalid. Option D uses a string instead of a color constant. Option D misses the required onDismissed callback.
❓ lifecycle
advanced2:00remaining
What happens if you reuse the same Key for multiple Dismissible widgets?
In a list of Dismissible widgets, what is the effect of assigning the same Key to more than one Dismissible?
Attempts:
2 left
💡 Hint
Keys help Flutter identify widgets uniquely in the widget tree.
✗ Incorrect
Keys must be unique among sibling widgets to avoid conflicts. Reusing keys causes Flutter to throw an exception during build.
advanced
2:00remaining
How to navigate after dismissing an item in a Dismissible?
You want to navigate to a new screen after an item is dismissed. Where should you place the navigation code?
Attempts:
2 left
💡 Hint
Think about when the dismissal action completes.
✗ Incorrect
The onDismissed callback is called after the swipe completes and the item is removed. This is the right place to trigger navigation.
🔧 Debug
expert2:00remaining
Why does the Dismissible widget not dismiss when swiped?
You have this code but swiping the item does not remove it or call onDismissed:
Dismissible(
key: Key('item3'),
child: ListTile(title: Text('Swipe me')),
onDismissed: (direction) {
print('Dismissed');
},
)
What is the most likely cause?
Attempts:
2 left
💡 Hint
Dismissible removes the widget visually but the list must update to reflect the change.
✗ Incorrect
Dismissible only removes the widget from the UI temporarily. The underlying data list must be updated to remove the item; otherwise, the widget will reappear on rebuild.