flutter - 如何设置团队内切换分数按钮的值?
问题描述
如何为每个团队设置切换分数按钮的值?
例如,当团队 A 被按下时,用户可以从得分按钮中进行选择。此外,如果按下团队 B,则用户可以从得分按钮中进行选择。但只有被选中的球队才能获得积分。
void scoreTeamA() {
setState(() {
outputTeamA += _choiceA;
});
}
void scoreTeamB() {
setState(() {
outputTeamB += _choiceB;
});
}
团队按钮
ToggleButtons(
children: [
Container(
child: Text(
'team A',
textScaleFactor: 3,
),
),
Text(
'team B ',
textScaleFactor: 3,
),
],
onPressed: (int index) {
setState(() {
for (int buttonIndex = 0;
buttonIndex < isSelected1.length;
buttonIndex++) {
if (buttonIndex == index) {
isSelected1[buttonIndex] = true;
} else {
isSelected1[buttonIndex] = false;
}
}
});
},
分数按钮
ToggleButtons(
children: [
Text('5'),
Text('6'),
Text('7'),
],
onPressed: (int index) {
setState(() {
isSelected2[index] = !isSelected2[index];
switch (index) {
case 0:
_choiceA = 5;
_choiceB = 5;
break;
case 1:
_choiceA = 6;
_choiceB = 6;
break;
case 2:
_choiceA = 7;
_choiceB = 7;
break;
}
});
},
isSelected: isSelected2,
),
赢按钮
MaterialButton(
shape: CircleBorder(
side: BorderSide(
color: Colors.black,
width: 1.0,
style: BorderStyle.solid)),
color: Colors.blue,
onPressed: () {
setState(() {
scoreTeamA();
scoreTeamB();
});
},
child: Text(
'win',
textScaleFactor: 3,
),
),
谢谢穆罕默德
解决方案
可以使用的信息很少,但我会尝试:
children: [
isSelected1[0] ? Text('5') : Text('five'),
Text('6'),
Text('7'),
],
这应该让你看到一些变化。从那里你应该能够完成其余的工作。
推荐阅读
- linux-kernel - initramfs 没有模块
- eclipse - stale deployment in WAS
- gitlab - GitLab CI/CD pipeline, deploy to Windows Server
- android - AndroidX 中的 BottomSheetBehavior
- ios - 应用程序关闭时如何在本地通知上打开 VC
- ios - Position Navigation Bar top of the safe area
- python - SMTPServer Disconnected: Connection unexpectedly closed
- regex - 正则表达式 - 如何处理单词边界问题?
- javascript - 如何通过 youtube 等排序检索最后一个订阅者?
- javascript - 我正在使用 react-image-crop 和 react 和 Express 来上传带有 Crop 的个人资料图片