是否可以动态禁用flutter_swiper的滑动几秒钟?

时间:2020-11-10 22:14:44

标签: flutter

我在我的应用程序中使用flutter_swiper 1.1.6来显示图像。但是对于某些索引,我想禁用刷卡刷动几秒钟。

这是我的代码:

Swiper(
  index: inx,
  itemCount: swiperList.length,
  itemWidth: double.infinity,
  loop: false,
  viewportFraction: 0.85,
  scale: 0.8,
  itemBuilder: (context, index) {
    if(index == Indexer.CELL) {
      //disable swiping
    }

    return Container(...);
  },
);

1 个答案:

答案 0 :(得分:0)

您可以通过用AbsorbPointer或IgnorePointer包装小部件来禁用用户与小部件的交互几秒钟。请参阅下面的代码以供参考。

....
bool absorbing = false;
......

AbsorbPointer(
absorbing : absorbing,
child: Swiper(
  index: inx,
  itemCount: swiperList.length,
  itemWidth: double.infinity,
  loop: false,
  viewportFraction: 0.85,
  scale: 0.8,
  itemBuilder: (context, index) {
    if(index == Indexer.CELL) {
      setState(() { absorbing=true; });
      Future.delayed(const Duration(seconds: 5), () {
      setState(() { absorbing=false; });
     });
    }

    return Container(...);
  },
),);