Creating a shopping cart application with Redux
Create a new Flutter application named cart_redux
and copy item.dart
into your lib
folder, as we have been doing in the previous sections. Add dependencies for equatable
and flutter_redux
from pub.dev. Let's get started, as follows:
- Create a new file named
actions.dart
and add the following code to it:import 'item.dart'; class Actions {} class AddItemToCartAction extends Actions { final Item item; AddItemToCartAction({required this.item}); } class RemoveItemFromCartAction extends Actions { final Item item; RemoveItemFromCartAction({required this.item}); }
Both of these actions are self-explanatory; we will be using these to trigger the addition/removal of items to and from the cart.
- Create a file named
cart_state.dart
and add the following code to it:import 'package:equatable/equatable.dart'; import 'package:redux/redux.dart'; import 'actions...