Flutter错误:RangeError(索引):无效值:不在0..2范围内,包括:3 in Swiper

问题描述 投票:0回答:1

我正在使用Swiper抖动,当我在列表中添加4个元素时发生错误。

我引用了链接Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3,但无法在Swiper中实现。

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),
        ]),
      ),
    );
  }
}
flutter flutter-layout flutter-animation flutter-test
1个回答
0
投票

用户stateCount为3。

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

我不知道其背后的原因,但确实有效。如果有人能解释这个神秘的3背后的原因,我将感到非常高兴。

© www.soinside.com 2019 - 2024. All rights reserved.