当新项目出现在屏幕上时,我想制作一个水平列表视图并更改背景颜色像这样 我无法使用列表视图,因为我无法根据当前项目索引更改容器颜色关于如何做的任何想法这个?
PS. 我制作了一个动画容器,它的子元素是页面视图,但我想要的是列表视图而不是页面视图
class _MyHomePageState extends State<MyHomePage> {
int _index = 0;
List<Color> colors = [
Colors.yallow,
Colors.blue
];
@override
Widget build(BuildContext context) {
final restData = Provider.of<ResturantsProvider>(context);
final rest = restData.rest;
return Scaffold(
body: AnimatedContainer(
duration: Duration(microseconds: 300),
curve: Curves.linear,
color: colors[_index],
child: PageView.builder(
onPageChanged: (i) {
setState(() {
_index = i;
});
},
scrollDirection: Axis.horizontal,
itemCount: rest.length,
itemBuilder: (context, index) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 50,
),
LogoHomePage(
logoImg: rest[index].logoImg,
),
ResturantListView(
restImg: rest[index].restImg,
restName: rest[index].restName,
restRate: rest[index].restRate,
restType: rest[index].restType,
time: rest[index].time,
color: rest[index].color,
)
],
);
},
),
),
);
}
}