码迷,mamicode.com
首页 > 其他好文 > 详细

flutter控件之RadioButton

时间:2018-12-19 17:52:49      阅读:642      评论:0      收藏:0      [点我收藏+]

标签:child   uil   code   caff   turn   center   int   change   tst   

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

标签:child   uil   code   caff   turn   center   int   change   tst   

原文地址:https://www.cnblogs.com/zhujiabin/p/10144588.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!