[英]RangeError (index): Invalid value: Not in range 0..7, inclusive: 8
You've set the itemCount attribute of the ListView with _ListFamilyPageState.data.body.family.length and you've use the index of it's builder with another list data.body.friends[index].id.toString()您已经使用 _ListFamilyPageState.data.body.family.length 设置了 ListView 的 itemCount 属性,并且您已经将其构建器的索引与另一个列表 data.body.friends[index].id.toString() 一起使用
I don't think both have the same number of elements我不认为两者具有相同数量的元素
The error is in your ListViewBuilder:错误在您的 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),
)));
},
)
You specified that there are family.length
items (in your data: 15), but you are pulling actual data from friends[index]
(8 items in your data).您指定了family.length
项目(在您的数据中:15),但您正在从family.length
friends[index]
中提取实际数据(您的数据中有 8 个项目)。
This gives you RangeError when rendering item at index 8.当在索引 8 处渲染项目时,这会给你 RangeError。
On top of that: you use static data in your state:最重要的是:您在您的状态中使用静态数据:
class _ListFamilyPageState extends State<ListFamily> {
static Relations data;
// ...
}
Don't do that.不要那样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.