flutter控件之RadioButton

Posted zhujiabin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了flutter控件之RadioButton相关的知识,希望对你有一定的参考价值。

import package:flutter/material.dart;
class LearnRadioButton extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return new _LearnRadioButton();
  }
}
class _LearnRadioButton extends State<LearnRadioButton>{
  int groupValue=1;
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          new Radio(value: 0, groupValue: 0, onChanged: null),//onChanged为null表示按钮不可用
          new Radio(
              value: 1,
              groupValue: groupValue,//当value和groupValue一致的时候则选中
              activeColor: Colors.red,
              onChanged: (T){
                updateGroupValue(T);
              }
          ),
          new Radio(
              value: 2,
              groupValue: groupValue,
              onChanged: (T){
                updateGroupValue(T);
              }
          ),
          new Radio(
              value: 3,
              groupValue: groupValue,
              onChanged: (T){
                updateGroupValue(T);
              }
          ),
          new Radio(
              value: 4,
              groupValue: groupValue,
              onChanged: (T){
                updateGroupValue(T);
              }
          ),
          new Radio(
              value: 5,
              groupValue: groupValue,
              onChanged: (T){
                updateGroupValue(T);
              }
          ),
          new Radio(
              value: 6,
              groupValue: groupValue,
              onChanged: (T){
                updateGroupValue(T);
              }
          ),
          new RadioListTile(
              value: 7,
              groupValue: groupValue,
              title: new Text(小张),
              onChanged: (T){
                updateGroupValue(T);
              }),
          new RadioListTile(
              value: 8,
              groupValue: groupValue,
              title: new Text(小林),
              onChanged: (T){
                updateGroupValue(T);
              }),
          new RadioListTile(
              value: 9,
              groupValue: groupValue,
              title: new Text(小王),
              onChanged: (T){
                updateGroupValue(T);
              }),
          new RadioListTile(
              value: 10,
              groupValue: groupValue,
              title: new Text(小红),
              onChanged: (T){
                updateGroupValue(T);
              })
        ],
      ),
    );
  }

  void updateGroupValue(int v){
    setState(() {
      groupValue=v;
    });
  }

}

 

以上是关于flutter控件之RadioButton的主要内容,如果未能解决你的问题,请参考以下文章

UI控件之RadioButton(单选按钮)&Checkbox(复选按钮)

Android控件之RadioButton

WPF 基础控件之 RadioButton 样式

Android基本控件之RadioGroup

RadioGroup结合RadioButton使用切换Fragment片段

背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch