Im getting error because of null safety. " _cart[index] += 1;" in this line from operation part (+=). The error is : The method '+' can't be unconditionally invoked because the receiver can be 'null'.
class CartBloc with ChangeNotifier { Map<int, int> _cart= {};
Map<int, int> get cart => _cart;
void addToCart(index) {
if (_cart.containsKey(index)) {
_cart[index] += 1;
} else {
_cart[index] = 1;
}
notifyListeners();
}