我正在使用 carousel_slider:^ 2.2.1 ,目前我正在从api获取此数据,
List<Map<String, dynamic>> data = [
{
"id": "001",
"nombre": "Image 1",
"imagen":
"https://cdn-images-1.medium.com/max/2000/1*GqdzzfB_BHorv7V2NV7Jgg.jpeg",
"time": 20
},
{
"id": "002",
"nombre": "Image 2",
"imagen":
"https://cdn-images-1.medium.com/max/2000/1*GqdzzfB_BHorv7V2NV7Jgg.jpeg",
"time": 5
},
{
"id": "003",
"nombre": "Image 3",
"imagen":
"https://cdn-images-1.medium.com/max/2000/1*GqdzzfB_BHorv7V2NV7Jgg.jpeg",
"time": 15
}
];
我已经使用文档中的示例成功实现了旋转木马
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) {
data.forEach((imageUrl) {
precacheImage(NetworkImage(imageUrl), context);
});
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('image slider demo')),
body: Container(
child: CarouselSlider.builder(
itemCount: data.length,
options: CarouselOptions(
autoPlay: true,
aspectRatio: 2.0,
enlargeCenterPage: true,
),
itemBuilder: (context, index) {
return Container(
child: Center(
child: Image.network(data[index].imagen, fit: BoxFit.cover, width: 1000)
),
);
},
)
),
);
}
}
但是我想知道如何添加属性“ time”(秒)。当轮播移动新图像时,我想更改图像的显示持续时间。 目的是自定义图像的显示时间
答案 0 :(得分:0)
在CarouselSlider中添加autoPlayAnimationDuration: Duration(milliseconds: 500),
。