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_getx
and add dependencies for GetX from pub.dev. - Copy the
item.dart
file from the previous chapter's code into thelib
folder of yourcart_getx
app. Make sure to add the dependency for theequatable
package from pub.dev. - Create a new file named
cart_controller.dart
and 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
Item
class work:import 'item.dart';
- In the same
cart_controller.dart
file, underneath theCart
class, add the...