欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Flutter基础组件RadioListTile

程序员文章站 2022-05-30 19:32:48
...

标题Flutter基础组件RadioListTile

1.组件属性介绍
Flutter基础组件RadioListTile
2.不同属性效果比较
Flutter基础组件RadioListTile
3.完整代码

///单选列表
class RadioListTileView extends StatefulWidget {
  @override
  _RadioListTileViewState createState() => _RadioListTileViewState();
}

class _RadioListTileViewState extends State<RadioListTileView> {
  String defaultValue = "A";

  onChange(value) {
    if (mounted)
      setState(() {
        defaultValue = value;
      });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("RadioListTileView"),
      ),
      body: Column(
        children: <Widget>[
          Container(
            color: Colors.red,
            child: RadioListTile<String>(
              value: "A",
              title: Text("A选项"),
              subtitle: Text(
                "A选项的二级标签项",
                style: TextStyle(fontSize: 16),
              ),
              dense: false,
              isThreeLine: true,
//              secondary: Text("这是一个居右的组件"),
              secondary: Icon(Icons.send),
              selected: true,
              groupValue: defaultValue,
              onChanged: (v) => onChange(v),
            ),
          ),
          Container(
            color: Colors.green,
            child: RadioListTile<String>(
              value: "B",
              title: Text("B选项"),
              subtitle: Text(
                "B选项的二级标签",
                style: TextStyle(fontSize: 16),
              ),
              dense: true,
              groupValue: defaultValue,
              onChanged: (v) => onChange(v),
            ),
          ),
          RadioListTile<String>(
            value: "C",
            title: Text("C选项"),
            subtitle: Text(
              "C选项的二级标签",
              style: TextStyle(fontSize: 16),
            ),
            groupValue: defaultValue,
            onChanged: (v) => onChange(v),
          )
        ],
      ),
    );
  }
}

4.补充:选中颜色属性activeColor
Flutter基础组件RadioListTile

相关标签: Flutter