mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
Added trailing button to delete cart item in provider_shopper App (#571)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user