美文网首页
Flutter 单选框使用 Radio RadioListTil

Flutter 单选框使用 Radio RadioListTil

作者: 浩仔_Boy | 来源:发表于2020-11-30 14:55 被阅读0次

单选框使用 Radio RadioListTile Switch

import 'package:flutter/material.dart';
import '../widgets/BaseThemeBar.dart';

class RadioDemoPage extends StatefulWidget {
  @override
  _RadioDemoPageState createState() => _RadioDemoPageState();
}

class _RadioDemoPageState extends State<RadioDemoPage> {
  int sex = 1;
  var flag = true;
  @override
  Widget build(BuildContext context) {
    return getBaseThemeBar(
        'Radio RadioListTile Swith',
        Padding(
          padding: EdgeInsets.all(10),
          child: Column(
            children: [
              Row(
                children: [
                  Text('男:'),
                  Radio(
                      value: 1,
                      groupValue: this.sex,
                      onChanged: (v) {
                        setState(() {
                          this.sex = v;
                        });
                      }),
                  SizedBox(
                    width: 20,
                  ),
                  Text('男:'),
                  Radio(
                      value: 2,
                      groupValue: this.sex,
                      onChanged: (v) {
                        setState(() {
                          this.sex = v;
                        });
                      }),
                ],
              ),
              Row(
                children: [Text(this.sex == 1 ? "选中的男" : "选中的女")],
              ),
              SizedBox(),
              RadioListTile(
                  value: 1,
                  groupValue: this.sex,
                  title: Text('标题'),
                  subtitle: Text('二级标题'),
                  secondary: Icon(Icons.home),
                  selected: this.sex == 1,
                  onChanged: (v) {
                    setState(() {
                      this.sex = v;
                    });
                  }),
              RadioListTile(
                  value: 2,
                  groupValue: this.sex,
                  title: Text('标题'),
                  subtitle: Text('二级标题'),
                  secondary: Icon(Icons.home),
                  selected: this.sex == 2,
                  onChanged: (v) {
                    setState(() {
                      this.sex = v;
                    });
                  }),
              SizedBox(
                height: 40,
              ),
              Switch(
                  value: this.flag,
                  onChanged: (v) {
                    setState(() {
                      this.flag = v;
                    });
                  })
            ],
          ),
        ));
  }
}

相关文章

网友评论

      本文标题:Flutter 单选框使用 Radio RadioListTil

      本文链接:https://www.haomeiwen.com/subject/yfwrwktx.html