Step 5

Key points:

  • Use a Dismissible widget to allow an item in a list to be deleted.
  • Each Dismissable must have a unique key.
  • You can use a SnackBar to give feedback to your users.

Solution:

In the itemBuilder of the ListView.builder, in the build() method of the _ItemsScreenState class in the items_screen.dart file, add a Dismissible widget, as follows:

 itemBuilder: (BuildContext context, int index) {
return Dismissible(
key: Key(items[index].name),
onDismissed: (direction) {
String strName = items[index].name;
helper.deleteItem(items[index]);
setState(() {
items.removeAt(index);
});
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text("$strName
deleted")));
},
child: ListTile(

The app is now complete. There's only one more step to perform: making sure that it works as expected.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.12.207