Creating a shopping cart application with BLoC
We will be reusing the same screens we created in the previous chapter, with some editions specific to BLoC. Let's begin creating our shopping cart application using BLoC, as follows:
- Create a new Flutter application named
cart_bloc
. - Copy the
item.dart
file from the previous chapter's code into thelib
folder of yourcart_bloc
application. We will be reusing this file in all upcoming applications. - Create a new file named
cart_event.dart
and add the following code to it:import 'item.dart'; class CartEvent {} class AddItemToCartEvent extends CartEvent { final Item item; AddItemToCartEvent({required this.item}); } class RemoveItemFromCartEvent extends CartEvent { final Item item; RemoveItemFromCartEvent({required this.item}); }
We created two events for our cart, one for adding an item to the cart and one for removing an item from the cart.
- Create a new...