title: RangeError (index): Invalid value: Valid value range is empty: 0, get this Error on deleting last image flutter:-
body: <p>I have five images and when I tap on any image, it opens in full screen and we can swipe to other image left/right, and when I delete any image the particular image gets deleted and then it goes to next image, till now it is working fine but when there is only image left after deleting all other and when I delete that one single image too it gives ERROR: RangeError (index): Invalid value: Valid value range is empty: 0. How to delete that last image from index.Pls help... Thanks.</p>
  <pre><code>  Widget deleteBtn(BuildContext context) {
    final auth = FirebaseAuth.instance;
  return new Padding(
  padding: const EdgeInsets.all(10.0),
  child: IconButton(
  icon: Icon(
    Icons.delete_forever_outlined,
    color: const Color(0xFF227770),
    size: 35,
  ),
  onPressed: () async {
    var fileUrl =
    Uri.decodeFull(Path.basename(widget.imageList[_currentIndex]))
        .replaceAll(new RegExp(r'(\?alt).*'), '');
    try {
      firebase_storage.Reference photoRef = await firebase_storage.FirebaseStorage.instance
          .ref().storage.refFromURL(widget.imageList[_currentIndex]);
  
      await photoRef.delete().then((value)  {
        widget.imageList.removeAt(_currentIndex);
  
        _pageController.nextPage(duration: Duration(milliseconds: 10) , curve: Curves.easeInOut);
  
      });
    } catch (e) {
      print(e);
      print(&quot;Cant delete&quot; +e);
       }
    FirebaseFirestore.instance
        .collection(&quot;users&quot;)
        .doc(auth.currentUser.uid)
        .update({
      &quot;images&quot;: FieldValue.arrayRemove([widget.imageList[_currentIndex]])
    });
  },
  ),
    );
  
    }
  </code></pre>