我正在尝试通过按下按钮来更改容器的颜色。它查看布尔值并确定颜色。但如何独立地为每个列表视图项更改布尔值呢?
我也在使用Provider进行状态管理。这只是我尝试做的事情的一种示例。
我也在使用Provider进行状态管理。这只是我尝试做的事情的一种示例。
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
bool colorToggle = false;
return MaterialApp(
home: Scaffold(
body: ListView.builder(
itemCount: 10,
itemBuilder: (context, i) {
return Container(
width: 100,
height: 100,
color: colorToggle ? Colors.blue : Colors.green,
child: GestureDetector(
onTap: () {
//how to change the colorToggle independendently with each listview item?
print('tapped');
},
child: Text('change color'),
),
);
},
),
),
);
}
}