Creating a cart app with GetX
We will be reusing the same screens we created in the previous chapters, with some editions specific to GetX. Let's begin by creating our cart application using GetX:
- Create a new Flutter app named
cart_getxand add dependencies for GetX from pub.dev. - Copy the
item.dartfile from the previous chapter's code into thelibfolder of yourcart_getxapp. Make sure to add the dependency for theequatablepackage from pub.dev. - Create a new file named
cart_controller.dartand add the following class:class Cart { List<Item> items = populateItems(); List<Item> cart = []; Cart({required this.cart}); }This is a very simple, self-explanatory class that holds our static item list and an initially empty cart.
Don't forget to add the following import in order to make the
Itemclass work:import 'item.dart';
- In the same
cart_controller.dartfile, underneath theCartclass, add the...