zoukankan      html  css  js  c++  java
  • 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;
        });
      }
    
    }
  • 相关阅读:
    Jenkins+gitlab自动化构建部署
    浅尝CI/CD,真香
    各种奇葩,我感觉我快窒息了,来吐吐槽...
    用SMART原则来创建一个好的OKR
    用OKR改变个人能力得不到明显提升的困境
    承诺型与愿景型,什么样的OKR适合你?
    OKR文化:关键成果必须具备的五个特点
    为什么不能完全用OKR替代KPI?
    OKR的激励方式应该注意什么?
    OKR如何与绩效考核并行?
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/10144588.html
Copyright © 2011-2022 走看看