zoukankan      html  css  js  c++  java
  • flutter Radio单选框

    单选框,允许用户从一组中选择一个选项。

    import 'package:flutter/material.dart';
    
    class RadioDemo extends StatefulWidget {
      @override
      _RadioDemoState createState() => _RadioDemoState();
    }
    
    class _RadioDemoState extends State<RadioDemo> {
      int _radioGroupA = 0;
      
      void _handleRadioValueChanged(int value) {
        setState(() {
          _radioGroupA = value;
        });
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('RadioDemo'),
            elevation: 0.0,
          ),
          body: Container(
            padding: EdgeInsets.all(16.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text('RadioGroupValue: $_radioGroupA'),
                SizedBox(height: 32.0),
                RadioListTile(
                  value: 0,
                  groupValue: _radioGroupA,
                  onChanged: _handleRadioValueChanged,
                  title: Text('Options A'),
                  subtitle: Text('Description'),
                  secondary: Icon(Icons.filter_1),
                  selected: _radioGroupA == 0,
                ),
                RadioListTile(
                  value: 1,
                  groupValue: _radioGroupA,
                  onChanged: _handleRadioValueChanged,
                  title: Text('Options B'),
                  subtitle: Text('Description'),
                  secondary: Icon(Icons.filter_2),
                  selected: _radioGroupA == 1,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    // Radio(
                    //   value: 0,
                    //   groupValue: _radioGroupA,
                    //   onChanged: _handleRadioValueChanged,
                    //   activeColor: Colors.black,
                    // ),
                    // Radio(
                    //   value: 1,
                    //   groupValue: _radioGroupA,
                    //   onChanged: _handleRadioValueChanged,
                    //   activeColor: Colors.black,
                    // ),
                  ],
                ),
              ],
            ),
          )
        );
      }
    }

    文档:https://api.flutter.dev/flutter/material/Radio-class.html

    效果:

  • 相关阅读:
    洛谷P3819 松江1843路
    洛谷P1896 [SCOI2005]互不侵犯King
    洛谷P1197 [JSOI2008]星球大战
    洛谷P1171 售货员的难题
    2017-10-24 NOIP模拟赛
    LibreOJ #6192. 「美团 CodeM 复赛」城市网络
    洛谷P2258 子矩阵
    Cogs 9. 中心台站建设
    Cogs 6. 线型网络
    洛谷P3138 [USACO16FEB]负载平衡Load Balancing_Silver
  • 原文地址:https://www.cnblogs.com/loaderman/p/11344937.html
Copyright © 2011-2022 走看看