英文:
Carousal slider image is not taking width properly in flutter
问题
以下是翻译好的代码部分:
CarouselSlider(
options: CarouselOptions(
onPageChanged: (index, reason) {
setState(() {
_current = index;
});
},
autoPlayAnimationDuration: Duration(seconds: 1),
autoPlayCurve: Curves.easeInOut,
autoPlay: true,
),
items: images.map((i) {
return PageView(
controller: controller,
physics: BouncingScrollPhysics(),
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
),
child: Image.asset(i, fit: BoxFit.fitWidth, width: 350),
),
],
);
}).toList(),
),
请注意,我只翻译了代码部分,没有包括注释或其他内容。
英文:
I want like this
And I got this
CarouselSlider(
options: CarouselOptions(
onPageChanged: (index, reason) {
setState(() {
_current = index;
});},
autoPlayAnimationDuration:Duration(seconds: 1),
autoPlayCurve: Curves.easeInOut,
autoPlay: true,
// height: 200,
// initialPage: 0,
// enlargeCenterPage: true,
),
items: images.map((i) {
return PageView(
controller: controller,
physics: BouncingScrollPhysics(),
children: [
Container(
// margin: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
// image: DecorationImage(
// image:AssetImage(i),
// fit: BoxFit.fill,
// ),
),
child: Image.asset(i,fit: BoxFit.fitWidth, width: 350),
),
]
);
}).toList(),
),
答案1
得分: 0
你可以通过在CarouselOptions
内使用viewportFraction: 1.0
来修复它。
英文:
you can fix it by using viewportFraction: 1.0,
inside the CarouselOptions
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论