我有一个ScrollablePositionedList,并且我想在触摸事件期间更新每个可见列表项的背景颜色。我可以更改列表中所选项目的背景颜色,但发现很难访问/更新列表中的所有其他项目。
这是我到目前为止所拥有的,
body: SizedBox(
height: 100,
child: WillPopScope(
onWillPop: () {
var position = itemPositionsListener.itemPositions.value.first.index;
print(position);
//trigger leaving and use own data
Navigator.pop(context, false);
//we need to return a future
return Future.value(false);
},
child: ScrollablePositionedList.builder(
scrollDirection: Axis.horizontal,
physics: NeverScrollableScrollPhysics(),
initialScrollIndex: startPosition,
itemScrollController: itemScrollController,
itemPositionsListener: itemPositionsListener,
itemCount: 14,
itemBuilder: (context, index) =>
MonthTile(getWidth(), months[index],(MonthTile tile){
itemScrollController.scrollTo(
index: getPosition(index),
duration: Duration(seconds: 1),
curve: Curves.easeInOutCubic);
// }
})))
),
我的主要目的是在选择另一个项目时将所选项目恢复为其原始颜色。我想我的问题是,是否可以使用一个小部件来完成此任务?