Flutter Widget之Radio

Widget:https://flutter.io/docs/development/ui/widgets
Radio:https://docs.flutter.io/flutter/material/Radio-class.html
     

import 'package:flutter/material.dart';

class RadioButtonDemoPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new _RadioButtonDemoPageState();
  }
}

class _RadioButtonDemoPageState extends State<RadioButtonDemoPage> {
  int groupValue = 1;
  String sGroupValue = '';

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(
        title: Text('RadioButton Demo'),
      ),
      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 RadioListTile(
              value: 'Joe.Ye',
              groupValue: sGroupValue,
              title: new Text('Joe.Ye'),
              onChanged: (T) {
                updateStringGroupValue(T);
              }),
          new RadioListTile(
              value: 'Android',
              groupValue: sGroupValue,
              title: new Text('Android'),
              secondary: const Icon(Icons.favorite),
              onChanged: (T) {
                updateStringGroupValue(T);
              }),
          new RadioListTile(
              value: 'iOS',
              groupValue: sGroupValue,
              title: new Text('iOS'),
              onChanged: (T) {
                updateStringGroupValue(T);
              }),
        ],
      ),
    );
  }

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

  void updateStringGroupValue(String v) {
    setState(() {
      sGroupValue = v;
    });
  }
}

Flutter Widget Radio

上一篇 Flutter Widget之Checkbox
下一篇 Flutter Widget之Switch
目录
文章列表
1 RecyclerView实现设置最大高度maxHeight
RecyclerView实现设置最大高度maxHeight
2
Prometheus通过Consul动态修改Targets接入
Prometheus通过Consul动态修改Targets接入
3
Python列表
Python列表
4
以太坊买狗流程
以太坊买狗流程
5
编译WebRTC for Android
编译WebRTC for Android
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。