每当我同时单击Listview的多个项目时,print
就会被多次调用。如何在不使用锁定布尔值的情况下一次仅使Listview的一个子项可单击?
class MyHomePage extends StatelessWidget {
final List cards =
new List.generate(6, (int i) => MyCard(testVariable: i)).toList();
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new ListView(
children: cards,
),
);
}
}
class MyCard extends StatelessWidget {
final testVariable;
MyCard({@required this.testVariable});
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(16.0, 8.0, 16.0, 0.0),
child: Card(
child: new InkWell(
onTap: () {
print(testVariable);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(padding: EdgeInsets.all(100.0), child: Text(testVariable.toString()))
],
),
),
),
);
}
}