如何在Flutter中默认选中的扩展图块列表中设置单选按钮?

时间:2019-10-11 03:55:05

标签: flutter

我有一个扩展图块列表,每个图块都有3个单选按钮。我想设置页面加载时默认选中的一些单选按钮。我怎样才能做到这一点?请帮忙。

RadioButtonGroup(
              activeColor: Color(ProjectColors.mainColor),
              labelStyle: TextStyle(
                fontFamily: "AN",
                fontSize: 16,
                fontWeight: FontWeight.w400,
                color: Color(ProjectColors.secondaryColor),
              ),
              labels: _role.values.map((x) => x.title).toList(),
             )

1 个答案:

答案 0 :(得分:0)

代码如下:

String _picked = "Two"; //a variable _picked declared

RadioButtonGroup(
          orientation: GroupedButtonsOrientation.HORIZONTAL,
          margin: const EdgeInsets.only(left: 12.0),
          onSelected: (String selected) => setState((){
            _picked = selected;
          }),
          labels: <String>[
            "One",
            "Two",
          ],
          picked: _picked,
          itemBuilder: (Radio rb, Text txt, int i){
            return Column(
              children: <Widget>[
                Icon(Icons.public),
                rb,
                txt,
              ],
            );
          },
        ),

输出:

enter image description here