title: Cannot remove the last item in the ListView Flutter
body: <p>I have a ListView containing the observable list <code>var cartItems = &lt;CartItem&gt;[].obs;</code>, when I tried to remove the last item in the ListView, I got error <strong>RangeError (index): Invalid value: Valid value range is empty: 0</strong> and it was undone. Anyone can show me how to fix it? Thanks in advance. This is my code to hold the ListView:</p>
  <pre><code>return Obx(() {
        if (_cartController.isLoading == false) {
          if (_cartController.cartItems.length == 0) {
            return Center(
              child: Text(&quot;Your cart is empty.&quot;),
            );
          }
          return Scaffold(
            backgroundColor: Colors.white,
            body: ListView.separated(
              ...
              itemBuilder: (context, index) {
                return Slidable(
                  endActionPane: ActionPane(
                    motion: ScrollMotion(),
                    children: [
                      SlidableAction(
                        onPressed: (context) {
                          setState(() {
                            _cartController.cartItems.removeAt(index);
                          });
                          _cartController
                              .removeFromCart(
                                  userId: widget.user.id,
                                  productId:
                                      _cartController.cartItems[index].item.id)
                              .then((value) {...});
                        },
                        ...
                      ),
                    ],
                  ),
                  child: GestureDetector(
                    onTap: () =&gt; Get.to(() =&gt; ProductDetailsScreen(
                        product: _cartController.cartItems[index].item)),
                    child: _itemCard(
                        cartItem: _cartController.cartItems[index], index: index),
                  ),
                );
              },
              ...
            ),
            ...
          );
        } else {
          ...
        }
      });
  </code></pre>