Creating a shopping cart application with setState
Without any further ado, let's jump directly into the code, as follows:
- Create a new Flutter application in the same way as we have been doing in the previous chapters. Name this application
cart_set_state
. - Create a new file named
item.dart
and add a model class namedItem
, as follows:class Item { final String? name; final String? price; Item({this.name, this.price}); }
- In order to create sample data for our product list, we are creating a function that does the work for us. Add the following function below the
Item
class in theitem.dart
file:List<Item> populateItems() { return [ Item(name: 'Keyboard', price: '24'), Item(name: 'Mouse', price: '20'), Item(name: 'LED Screen', price: '44'), Item(name: &apos...