Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振切换按钮只能按一次_Flutter_Dart - Fatal编程技术网

Flutter 颤振切换按钮只能按一次

Flutter 颤振切换按钮只能按一次,flutter,dart,Flutter,Dart,目前,为了提高我在颤振方面的技能,我决定制作一个问答游戏。我刚刚实现了一些“赔率”,这是玩家在游戏中应该按下的3个按钮 然而,我只希望他们能够点击一次,而不是在按下按钮后切换答案 此外,我想存储切换按钮,这样,如果我再次打开屏幕,它仍然会显示相同的输入答案 到目前为止,我还没有太多关于颤振的经验,很抱歉用这样一个问题来打扰你们,但如果有人能帮我回答我的问题,那就太好了 非常感谢,祝你今天休息愉快, 亨利 这是我提出的代码-您可以随意更改任何内容: List<bool> _isSel

目前,为了提高我在颤振方面的技能,我决定制作一个问答游戏。我刚刚实现了一些“赔率”,这是玩家在游戏中应该按下的3个按钮

然而,我只希望他们能够点击一次,而不是在按下按钮后切换答案

此外,我想存储切换按钮,这样,如果我再次打开屏幕,它仍然会显示相同的输入答案

到目前为止,我还没有太多关于颤振的经验,很抱歉用这样一个问题来打扰你们,但如果有人能帮我回答我的问题,那就太好了

非常感谢,祝你今天休息愉快, 亨利

这是我提出的代码-您可以随意更改任何内容:

 List<bool> _isSelected = [false, false, false];
 bool buttonClicked = false;

ToggleButtons(
          children: <Widget>[
            _buildOddItem('1', widget.prematchFacts.odds.winHome),
            _buildOddItem('x', widget.prematchFacts.odds.draw),
            _buildOddItem('2', widget.prematchFacts.odds.winAway),
          ],
          color: Colors.white,
          borderColor: Colors.white,
          borderWidth: 2,
          disabledBorderColor: Colors.white,
          selectedBorderColor: Colors.white,
          disabledColor: Colors.white,
          selectedColor: Colors.black,
          fillColor: Colors.white,
          
          onPressed: (int index) {
            setState(() {
              for (int buttonIndex = 0;
                  buttonIndex < _isSelected.length;
                  buttonIndex++) {
                if (buttonIndex == index) {
                  _isSelected[buttonIndex] = true;
                } else {
                  _isSelected[buttonIndex] = false;
                }
              }
              ;
              buttonClicked = true;
            });
          },
          isSelected: _isSelected,
        ),
        SizedBox(height: 20),
        Center(
          child: Text(
            (() {
              if (buttonClicked == false) {
                return "What is the right answer??";
              }
              if (buttonClicked == true) {
                return "Nice! your answer is saved!  ";
              }
            })(),
            style: TextStyle(color: Colors.white),
            textAlign: TextAlign.center,
          ),
        )
Widget _buildOddItem(String leftText, double value) {
    return Padding(
      padding: EdgeInsets.only(left: 8, right: 8),
      child: Container(
        height: 60,
        width: 75,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            Text(
              leftText,
              style: TextStyle(
                fontFamily: kSpecialFontFamily,
                fontSize: 15,
              ),
            ),
            Text(
              '$value'.replaceAll('.', ','),
              style: TextStyle(
                fontFamily: kSpecialFontFamily,
                fontWeight: FontWeight.w500,
                fontSize: 30,
              ),
            ),
          ],
        ),
      ),
    );
  }
}