flutter - Flutter - 自动滚动到 CaroidrlSlider
问题描述
我正在尝试启用自动滚动到卡片。它应该垂直滚动。我希望 Autoscroll 无需任何用户操作即可工作。并在 5 秒内自动滚动。
这是我要滚动的代码的一部分:
Container(
width: 3000,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: CarouselSlider(
options: CarouselOptions(height: 150.0),
items: [1, 2, 3, 4, 5].map((i) {
return Builder(
builder: (BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(horizontal: 5.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: greenHex),
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(
top: 0, right: 10, left: 0, bottom: 8),
),
],
),
);
},
);
}).toList(),
),
),
),
谁能帮帮我?
解决方案
您需要在 Carousel Slider Options 中启用 autoPlay 并设置 autoPlayInterval。
例子:
CarouselSlider.builder(
options: CarouselOptions(
.
.
.
autoPlay: true,
autoPlayInterval: const Duration(seconds: 4),
enableInfiniteScroll: true,
),
),
推荐阅读
- javascript - 如果字符串仅包含空格,则匹配的正则表达式?
- python-3.x - Python中的季节性趋势分解?
- flask - jinja2.exceptions.UndefinedError: 'form' 未使用烧瓶和 WTF 定义
- json - 在 ReactJS 中设置多个搜索过滤器
- sql - 如何在没有 UNION 的情况下组合来自 2 个左连接的数据
- javascript - 将函数作为参数传递是如何在这里工作的?
- python - 在 keras 中绘制曲线给出 KeyError: 'accuracy'
- flutter - 如何使用 dart 包 pdf 从图像 dart 命令行创建 pdf
- postgresql - 通过匹配另一个表的所有列来更新一个表
- c++ - C++ 暴露私有对象的成员