flutter - 按下图像时如何暂停carousel_pro的自动播放?
问题描述
实际上,carousel_slider 具有完美运行的 pauseAutoPlayOnTouch,但我正在使用 Stateless Widget 组件进入 Stateful Widget。所以,我试图暂停使用 carousel_pro ,但我不知道如何解决这个问题。
有一个名为onImageTap的属性,这就是答案。
这是我设置 Carousel 配置的代码的一部分。
dotSpacing: 15.0,
dotColor: Colors.blueGrey[100],
dotIncreasedColor: Color.fromRGBO(203, 0, 0, 1),
autoplay: true,
autoplayDuration: Duration(seconds: 10),
indicatorBgPadding: 0.0,
dotBgColor: Colors.transparent,
borderRadius: true,
解决方案
dotSpacing: 15.0,
dotColor: Colors.blueGrey[100],
dotIncreasedColor: Color.fromRGBO(203, 0, 0, 1),
autoplay: false,
indicatorBgPadding: 0.0,
dotBgColor: Colors.transparent,
borderRadius: true,
编辑 -
提供解释——
当 imageTap 事件发生时,您必须设置自动播放属性。为此,请执行以下步骤
- 添加类属性
bool isAutoPlayEnabled = true
- 在 CarouselOptions 中,设置
autoplay: isAutoPlayEnabled
- onImageTap 做
setState(){ isAutoPlayEnabled = ! isAutoPlayEnabled; }
现在将重新创建小部件树,并暂停轮播页面。
另一种理论-我不知道它是否会起作用-尝试用旋转木马包装GestureDetector
并使用它onTap:
来设置isAutoPlayEnabled
推荐阅读
- c++ - 使用 for_each 删除向量的元素
- python - 在另一个函数中使用变量
- excel - 有没有办法在excel中计算工作时间
- postgresql - 在 postgres 中查询 pg_class 以获取索引名称时,为什么其中一些出现以 # 为前缀?
- r - 使用因子列在 r 中创建一个数值列
- javascript - 尝试使用javascript使用递归打印数字的阶乘,但没有给出预期的输出
- c++ - 为什么 if 语句没有打印出字符串?cpp
- vue.js - Vuetify v-treeview - 如何以编程方式打开节点?
- r - ggplot中的重叠丝带
- reason - 如何在 ReasonML 中将元组解构为 List.map?