我连续有5个按钮,我想为每个按钮分配一个值。另外,如果获胜,我想显示按钮的相同值,如果输掉,我想显示按钮的时间times(*)2。
如何为onPressed的每个按钮分配特定的值?
谢谢
int bab = 5;
int o = 0; // output
void Scorebab() {
setState(() {
o = o + bab;
});
}
5个不同按钮的示例
Container(
height: 80,
width: 80,
padding: EdgeInsets.all(3.0),
child: MaterialButton(
shape: CircleBorder(
side: BorderSide(
color: Colors.black,
width: 1.0,
style: BorderStyle.solid)),
color: selectedTalba == Talba.bab
? kActiveCardColor
: kInactiveCardColor,
onPressed: () {
Scorebab();
setState(() {
selectedTalba = Talba.bab;
});
},
child: Text(
'bab',
style: kLabelTextStyle,
),
),
),
得分输出
Expanded(
child: ReusableCard(
onPress: () {
setState(() {
selectedShary = Shary.Lihum;
});
},
color: kInactiveCardColor,
cardChild: CardChild(
label: '$o ',
),
),
),
输赢按钮
Expanded(
child: ReusableCard(
onPress: () {
setState(() {
selectedScore = Score.Lose;
});
},
color: selectedScore == Score.Lose
? kActiveCardColor
: kInactiveCardColor,
cardChild: CardChild(
label: 'lose',
),
),
),
Expanded(
child: ReusableCard(
onPress: () {
setState(() {
selectedScore = Score.Win;
});
},
color: selectedScore == Score.Win
? kActiveCardColor
: kInactiveCardColor,
cardChild: CardChild(label: 'win!'),
),
),