ChangeFavoritesModel? changeFavoritesModel;
void changeFavorites(int productId) {
favorites?[productId] = !favorites[productId];
DioHelper.postData(
url: FAVORITES,
data: {
'product_id': productId,
},
token: token,
).then((value) {
changeFavoritesModel = ChangeFavoritesModel.fromJson(value.data);
print(value.data);
emit(ShopSuccessChangeFavoritesState());
}).catchError((error) {
emit(ShopErrorChangeFavoritesState());
});
}
here,an error occurs:
favorites?[productId] = !favorites[productId];
and say:-
A nullable expression can't be used as a condition. (Documentation)
Try checking that the value isn't 'null' before using it as a condition.