【问题标题】:Flutter Error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3 in Swiper颤振错误:RangeError(索引):无效值:不在范围 0..2 内,包括:3 在 Swiper
【发布时间】:2023-03-03 18:24:01
【问题描述】:

我在颤振中使用 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),
        ]),
      ),
    );
  }
}

【问题讨论】:

  • 你可以尝试从索引0开始,你为什么从-1开始?
  • customLayoutOption: CustomLayoutOption(startIndex: 0,stateCount: nimage.length)

标签: flutter flutter-layout flutter-animation flutter-test


【解决方案1】:

用户 stateCount 为 3。

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

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

【讨论】:

    猜你喜欢
    • 2019-05-26
    • 1970-01-01
    • 2020-07-06
    • 2019-11-01
    • 2021-08-14
    • 2021-10-21
    • 2020-07-05
    • 1970-01-01
    • 2021-01-01
    相关资源
    最近更新 更多