颤振错误:范围错误(索引):无效值:不在范围 0.2 中,包括:3 在 Swipeper 中



我在颤振中使用 Swipeper,当我在列表中添加 4 个元素时发生错误。

我参考了链接颤振错误:范围错误(索引(:无效值:不在 0..2 范围内,包括:3,但无法在 Swipeper 中实现相同的内容。

class _LipsOutlineState extends State<LipsOutline> {
var nimage = ["img/1.png",
"img/2.png",
"img/3.png",
"img/4.png", <-- When I add this element
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: new Swiper(
itemBuilder: (BuildContext context, int index){
return new Image.asset(nimage[index],);
},
itemCount: nimage.length,
itemWidth: 200,
itemHeight: 100,
control: new SwiperControl(),
layout: SwiperLayout.CUSTOM,
customLayoutOption: CustomLayoutOption(startIndex: 0,stateCount: nimage.length) <-- Tried Changing here didnt work
.addRotate([0/180, 0.0, 0/180])
.addTranslate([
Offset(0.0, 0.0),
Offset(0.0, 0.0),
Offset(0.0, 0.0),
]),
),
);
}
}

用户stateCount为 3。

customLayoutOption: CustomLayoutOption(startIndex: 0,stateCount: 3)

我不知道背后的原因,但它奏效了。 如果有人能解释这个神秘的3背后的原因,我会很高兴

最新更新