Creating a cart app using Binder
Let's create our cart application using Binder. You will need to create a new Flutter app named cart_binder
, add a dependency for binder
and equitable
from pub.dev, and copy the item.dart
file from the previous section's code into your lib
folder. Let's get started:
- Create a new file named
cart_model.dart
and add the following imports first:import 'package:binder/binder.dart'; import 'item.dart';
- Add the following line for getting the static list of items to be shown on the main screen:
List<Item> items = populateItems();
- Add the
CartModel
class underneath theitems
variable declaration:class CartModel { List<Item> cart; CartModel({required this.cart}); }
This class is simple responsible for holding our
cart
variable:final cartRef = StateRef(CartModel(cart: [])); final cartViewLogicRef = LogicRef((scope) => CartViewLogic(scope));
As we studied in Chapter 5, Executing...