1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00

Added trailing button to delete cart item in provider_shopper App (#571)

This commit is contained in:
Alabhya
2020-10-30 23:28:48 +05:30
committed by GitHub
parent 2165099fc9
commit 0188371865
3 changed files with 16 additions and 3 deletions

View File

@@ -40,4 +40,11 @@ class CartModel extends ChangeNotifier {
// depend on it.
notifyListeners();
}
void remove(Item item) {
_itemIds.remove(item.id);
// Don't forget to tell dependent widgets to rebuild _every time_
// you change the model.
notifyListeners();
}
}

View File

@@ -46,6 +46,12 @@ class _CartList extends StatelessWidget {
itemCount: cart.items.length,
itemBuilder: (context, index) => ListTile(
leading: Icon(Icons.done),
trailing: IconButton(
icon: Icon(Icons.remove_circle_outline),
onPressed: () {
cart.remove(cart.items[index]);
},
),
title: Text(
cart.items[index].name,
style: itemNameStyle,

View File

@@ -73,7 +73,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0-nullsafety.4"
nested:
dependency: transitive
description:
@@ -120,7 +120,7 @@ packages:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.1"
version: "1.10.0-nullsafety.4"
stream_channel:
dependency: transitive
description:
@@ -164,5 +164,5 @@ packages:
source: hosted
version: "2.1.0-nullsafety.3"
sdks:
dart: ">=2.10.0-110 <2.11.0"
dart: ">=2.10.0-110 <=2.11.0-234.0.dev"
flutter: ">=1.16.0"