Reputation: 35
ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10))),
onPressed: () {
cubit.addItemToCart(
id: cubit.getCartModel!.data[index].id);
},
child: Text(LocaleKeys.addToCart.tr()),
)
I'm trying to add item to cart so this RangeError Appears to me if anyone know how to solve it, I'll Aprreciate his Effort
Upvotes: 0
Views: 47
Reputation: 398
Maybe this list is empty.
cubit.getCartModel!.data
and you are accessing it with
index=4
Upvotes: 0
Reputation: 3877
Your range error comes from this line
cubit.getCartModel!.data[index]
It tells you that index
is
cubit.getCartModel
This is a problem because you can only select list elements in a range from 0...length - 1
.
Upvotes: 0