Flutter — Swipe to delete — Part 2

In last tutorial we created a simple swipe to delete view. In this we are going to add some icons and colors to the background layout of the list item.
In the Dismissible class there is a argument called background. For that we can add style,colors or icons for the background view which is show when swipe. We have to pass Widget object for that parameter. So let get start…
First we create a Container and we are going to add Icon for that Container like this.
background: Container(alignment: AlignmentDirectional.centerEnd,color: Colors.red,child: Padding( padding: EdgeInsets.fromLTRB(0.0, 0.0, 10.0, 0.0), child: Icon(Icons.delete, color: Colors.white, ), ),),
In here we align our icon to the end and the center . Then it will show in the right end of the background view. We can make that view look more like delete view by adding red color to the background with white color icon..
Other than that you can the little mistake has been done here. We can swipe both left to right and right to left here. So we can restrict that. there is argument under the Dismissible class and we can assign DismissDirection.endToStart to make that swipe only right to left.
This is the full code
Hope you will get the how to add swipe to dismiss view to flutter list.
Video
The Flutter Pub is a medium publication to bring you the latest and amazing resources such as articles, videos, codes, podcasts etc. about this great technology to teach you how to build beautiful apps with it. You can find us on Facebook, Twitter, and Medium or learn more about us here. We’d love to connect! And if you are a writer interested in writing for us, then you can do so through these guidelines.


