I'm a newbie in Riverpod and currently I'm trying to use StateNotifierProvider for my cart screen and I wonder is there any way while incrementing or decrementing cart items I can change the specific quantity variable in CartModel and update state to show changes in quantity in cart screen
final cartListProvider2 =
StateNotifierProvider.autoDispose<CartList2,
AsyncValue<buyingOptionModel.BuyingOptionsModel>>((ref) {
return CartList2(); //init empty cart
});
class CartList2 extends
StateNotifier<AsyncValue<buyingOptionModel.BuyingOptionsModel>>
{
CartList2() : super(AsyncValue.loading()) {
_getData();
}
void _getData() async {
final json = await
ProductRepository().buyingOptions(product_id: 11361);
var data = buyingOptionModel.BuyingOptionsModel.fromJson(json);
state = await AsyncValue.guard(() async => await data);
}
void increment(int index) async {
state.value!.pricing![index].quantity =
state.value!.pricing![index].quantity! +
state.value!.pricing![index].moq!;
state == state ? print("same") : print("different");
}
void decrement(int index) async {}
}