【发布时间】:2022-11-12 00:28:19
【问题描述】:
尝试制作在第一个更改时更改的并行轮播滑块。我的第一种方法是从第一个中获取索引并在第二个中注入它,但我无法做到这一点。第二种方法是使用相同的控制器,但显然这不起作用。有没有人这样做过,请帮忙。 提前致谢。
SizedBox(
height: ...,
width: .... ,
child: CarouselSlider.builder(
itemCount: count,
itemBuilder: (context, index, realIndex) {
return StationItem(
station: allSectors.where((item) => item.iD == selectedSectorId).first.stations![index],
stationNumber: index+1,
changePage: _changePage,
changeTitle: _changeTitle);
},
carouselController: stationsCarouselController,
options: CarouselOptions(
onScrolled: (index){
setState(() => activeIndex = index as int);
},
initialPage: 0,
onPageChanged: (index, reason) {
setState(() => activeIndex = index);
},
viewportFraction: 1,
enableInfiniteScroll: true,
enlargeCenterPage: true,
)),
),
Column(
children: [
SizedBox(
width: ...,
height: ...,
),
SizedBox(
width: ...,
height: ...,
child: FittedBox(
child: IconButton(
onPressed: _next,
icon: Image.asset('assets/icons/Right_arrow.png'),
splashRadius:...))),
SizedBox(
width: ...,
height: ...,
),
],
),
SizedBox(
height: ...,
width: ...,
),
SizedBox(
height: ...,
width: ...,
child: AbsorbPointer(
child: CarouselSlider.builder(
itemCount: count,
itemBuilder: (context, index, realIndex) {
return StationLoadingImage(station: allSectors.where((item) => item.iD == selectedSectorId).first.stations![index]);
},
carouselController: stationsImageCarouselController,
options: CarouselOptions(
initialPage: activeIndex,
onScrolled: null,
onPageChanged: null,
viewportFraction: 1,
enableInfiniteScroll: true,
enlargeCenterPage: true,
)),
)
)
'''
【问题讨论】:
-
我尝试使用按钮而不是滑动。它在使用“AbsorbPointer”禁用另一个轮播时起作用,因此用户不能滑动另一个轮播,只有第一个的按钮会改变第二个。但是当用第二个不滑动改变第一个时仍然存在问题。请注意,第一个滑块的元素是按钮,因此无法禁用触摸。