我在字母列表上写了一个迭代,并使用"map"类将卡片放在屏幕上.
在代码中你可以看到我做了一行,并使用" map "将所有的用户板打印到了屏幕上.我想在里面添加一些逻辑,所以我需要获取元素的id(用于录制事件).
实际上,我希望获得userBoard上的元素的特定索引.
代码:
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Row(
children: userBoard
.map((element) => Stack(children: <Widget>[
Align(
alignment: Alignment(0, -0.6),
child: GestureDetector(
onTap: (() {
setState(() {
// print("element=${element.toString()}");
// print("element=${userBoard[element]}");
});
}),
child: SizedBox(
width: 40,
height: 60,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
child: Center(
child: Text(element,
style: TextStyle(fontSize: 30)),
)),
),
),
)
]))
.toList(),
)
],
),
}
Picture - each card is "element" of the map. I want to get the indexes for the function onTap.个