Creating a shopping cart application with Cubit
Cubit is a slight variant of BLoC. To create a shopping cart application using Cubit, create a new Flutter application named cart_cubit
and copy item.dart
and cart_state.dart
from the previous section's application into your lib
folder. Also, add dependencies for the equatable
and flutter_bloc
packages from pub.dev. Then, follow these steps:
- Replace the contents of the
cart_state.dart
file with the following code:import 'package:equatable/equatable.dart'; import 'item.dart'; class CartState extends Equatable { @override List<Object?> get props => []; } class CartListState extends CartState { final List<Item> cart; CartListState({this.cart = const []}); @override List<Object?> get props => [this.cart]; } class CartUpdatingState extends CartState {}
- Create a new file named
cart_cubit.dart
and add the following...