简体   繁体   中英

ItemList: RangeError (index): Invalid value: Valid value range is empty: 0

I know that many topics are created with this title, but there isnt an answer for this specific kind.

I get the following Error-Code: Error: RangeError (index): Invalid value: Valid value range is empty: 0

When there isnt any data in the REST-API the output is: []

I dont know why i get this error-message please help me to solve it...

body: blockitem.listitems == null
          ? Center(child: CircularProgressIndicator())
          : ItemList(),
ListView.builder(
      itemCount: blockitem.listitems[tab.currentTab] == null
          ? 0
          : selectedList.length,
      itemBuilder: (BuildContext context, int index) {
        return Card(
          elevation: 2.0,
          color: Colors.blue.shade50,
          child: ListTile(
            leading: getValidityIcon(
                selectedList[index].isValid,
                selectedList[index].targetAge),
            title: Text(selectedList[index].name),
            subtitle: Text(
                "Expires at: ${selectedList[index].expDate}"),
            trailing: Icon(
              Icons.arrow_forward_ios,
              color: Colors.green.shade400,
            ),
            onTap: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => ItemDetail(itemDetailed: selectedList[index]),
                ),
              );
            },
          ),
        );
itemCount: blockitem.listitems[tab.currentTab] == null

The output is not null. It is just empty. You can check it's size. So change your code like this;

blockitem.listitems.length == 0 ? .....

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