问题是我不能一个一个地滑动图像并显示三个图像。上图是我努力实现的目标。
在一个滑块中显示三个图像,然后逐个滑动到下一个,同时仍然显示三个图像
上面的图像鞋我的进步,它的外观是好的,但当我滑动它,它幻灯片三个图像在同一时间,下面是我的代码。
Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 50,
height: 400,
child: MaterialButton(
onPressed: () =>
buttonCarouselController.previousPage(
duration: const Duration(milliseconds: 300),
curve: Curves.linear),
child: const Icon(
size: 45.0,
Icons.arrow_back_ios,
color: Color.fromARGB(255, 98, 124, 133)),
),
),
Container(
width: widthDevice - 120,
height: 400,
child: CarouselSlider.builder(
itemCount: imageCount,
options: CarouselOptions(
autoPlay: true,
// aspectRatio: 3.0,
viewportFraction: 1,
),
carouselController: buttonCarouselController,
itemBuilder: (context, index, realIdx) {
final int first = index * 2;
final int second =
index <= (imageList.length / 2).ceil() - 1
? first + 1
: 0;
final int third =
index <= (imageList.length / 3).ceil() - 1
? first + 2
: 0;
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
crossAxisAlignment:
CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
children: [
Container(
width: widthDevice / 5,
height: widthDevice / 5,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
imageList[first]
['image']),
fit: BoxFit.cover)),
),
Container(
width: widthDevice / 5,
child: Padding(
padding:
const EdgeInsets.all(8.0),
child: Text(
imageList[first]
['description'],
style: GoogleFonts.montserrat(
textStyle: TextStyle(
fontSize: 14,
color: Color.fromARGB(
255, 51, 51, 51),
),
)),
),
),
],
),
SizedBox(
width: 35,
),
Column(
children: [
Container(
width: widthDevice / 5,
height: widthDevice / 5,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
imageList[second]
['image']),
fit: BoxFit.cover)),
),
Container(
width: widthDevice / 5,
child: Padding(
padding:
const EdgeInsets.all(8.0),
child: Text(
imageList[second]
['description'],
style: GoogleFonts.montserrat(
textStyle: TextStyle(
fontSize: 14,
color: Color.fromARGB(
255, 51, 51, 51),
),
)),
),
),
],
),
SizedBox(
width: 35,
),
Column(
children: [
Container(
width: widthDevice / 5,
height: widthDevice / 5,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
imageList[third]
['image']),
fit: BoxFit.cover)),
),
Container(
width: widthDevice / 5,
child: Padding(
padding:
const EdgeInsets.all(8.0),
child: Text(
imageList[third]
['description'],
style: GoogleFonts.montserrat(
textStyle: TextStyle(
fontSize: 14,
color: Color.fromARGB(
255, 51, 51, 51),
),
)),
),
),
],
),
],
),
],
);
},
)),
Container(
width: 50,
height: 400,
child: MaterialButton(
onPressed: () => buttonCarouselController.nextPage(
duration: const Duration(milliseconds: 300),
curve: Curves.linear),
child: const Icon(
size: 45.0,
Icons.arrow_forward_ios,
color: Color.fromARGB(255, 98, 124, 133)),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: imageList.asMap().entries.map((entry) {
return GestureDetector(
onTap: () => _controller.animateToPage(entry.key),
child: Container(
width: 55.0,
height: 8.0,
margin: EdgeInsets.symmetric(
vertical: 8.0, horizontal: 4.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: (Theme.of(context).brightness ==
Brightness.dark
? Color.fromARGB(255, 98, 124, 133)
: const Color.fromARGB(
255, 252, 200, 178))
.withOpacity(
_current == entry.key ? 0.9 : 0.4)),
),
);
}).toList(),
),
],
))
1条答案
按热度按时间nnt7mjpx1#
要幻灯片图像并排,你可以使用下面的代码为您的要求
你可以搜索这个插件以获得更多的细节
它还提供自动播放功能,
希望对你有帮助!