最佳答案
错误出现在您的ListViewBuilder中:
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: _ListFamilyPageState.data.body.family.length,
itemBuilder: (context, index) {
return Container(
height: 74.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: const Radius.circular(20.0),
bottomRight: const Radius.circular(20.0)),
),
width: MediaQuery.of(context).size.width - 50.0,
child: Center(
child: Text(
data.body.friends[index].id.toString(),
style:
TextStyle(fontSize: 24.0),
)));
},
)
您指定了
family.length
项(在您的数据中:15),但您是从
friends[index]
(数据中的8个项目)中提取实际数据。当在索引8处渲染项目时,这会给您RangeError。
最重要的是:您可以在状态下使用静态数据:
class _ListFamilyPageState extends State<ListFamily> {
static Relations data;
// ...
}
不要那样做
关于json - RangeError(索引):无效值:不在0..7范围内,包括8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60840078/