【发布时间】:2021-07-28 22:57:28
【问题描述】:
我知道很多主题都是用这个标题创建的,但没有针对这种特定类型的答案。
我收到以下错误代码: 错误:RangeError(索引):无效值:有效值范围为空:0
当 REST-API 中没有任何数据时,输出为:[]
我不知道为什么会收到此错误消息,请帮助我解决它...
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]),
),
);
},
),
);
【问题讨论】: