首页 > 解决方案 > 如何设置团队内切换分数按钮的值?

问题描述

如何为每个团队设置切换分数按钮的值?

例如,当团队 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,
                  ),
                ),


谢谢穆罕默德

标签: flutterdart

解决方案


可以使用的信息很少,但我会尝试:

                children: [
                  isSelected1[0] ? Text('5') : Text('five'),
                  Text('6'),
                  Text('7'),
                ],

这应该让你看到一些变化。从那里你应该能够完成其余的工作。


推荐阅读