简体   繁体   English

ItemList:RangeError(索引):无效值:有效值范围为空:0

[英]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我得到以下错误代码:错误:RangeError(索引):无效值:有效值范围为空:0

When there isnt any data in the REST-API the output is: []当 REST-API 中没有任何数据时,output 为:[]

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. output 不是 null。 It is just empty.它只是空的。 You can check it's size.你可以检查它的大小。 So change your code like this;所以像这样改变你的代码;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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