简体   繁体   中英

Flutter delete an item in ListView.builder onTap of a button

I've create a ListView.builder to allow the user to add multiple credit cards.
To delete of them he would just check the card, and press the button 'Delete a card'. Inside the class InputAddCarte I've created a widget called _getItemChecked where I select the checked card and once my button is pressed I use removeAt to delete it.
My problem is that it doesn't work, it keeps telling me:

The following RangeError was thrown building:
RangeError (index): Invalid value: Only valid value is 0: 1

While if you check in the consolde of my dartPad, when I print the index it's either 0 or 1 (hence why I put index-1 in the code). If someone could help me find what I am doing wrong would be super nice: Here is the code: https://dartpad.dev/b0aaaa2901aa3ac67426d9bdd885abb1

You forgot to decrease your variable 'value' by one when removing an item from the list!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM