Basic Syntax of Dismissible Widget
Dismissible(
key: UniqueKey(), // or any unique key for tracking items
child: YourContentWidget(),
background: YourBackgroundWidget(),
secondaryBackground: YourSecondaryBackgroundWidget(),
confirmDismiss: (DismissDirection direction) async {
// Your confirmation logic goes here
// Return true to allow dismissal, false to prevent it
return true;
},
onDismissed: (DismissDirection direction) {
// Your action when item is dismissed goes here
},
onResize: () {
// Your resize animation logic goes here (optional)
},
direction: DismissDirection.endToStart, // or other DismissDirection values
dragStartBehavior: DragStartBehavior.start, // or DragStartBehavior.down
)
Flutter – Dismissible Widget
The Dismissible widget in Flutter is used to create items that can be dismissed by swiping them off the screen. It’s commonly used in lists or grids where you want to provide a way for users to remove items with a swipe gesture. In this article, we are going to implement the Dismissible widget and explore some properties of it. A sample video is given below to get an idea about what we are going to do in this article.