Radio

基本属性

  1. const Radio({
  2. Key key,
  3. @required this.value, // 此单选按钮表示的值。
  4. @required this.groupValue, //一组单选按钮的当前选择值。如果该单选按钮的[value]与[groupValue]匹配,则认为该按钮已被选中。
  5. @required this.onChanged, //当用户选择此单选按钮时调用。单选按钮将[value]作为参数传递给这个回调。
  6. this.activeColor, //选择此单选按钮时要使用的颜色。
  7. this.focusColor,
  8. this.hoverColor, // 悬浮的颜色
  9. this.materialTapTargetSize,
  10. this.visualDensity, // 紧凑程度
  11. this.focusNode,
  12. this.autofocus = false,
  13. }) : assert(autofocus != null),
  14. super(key: key);

基本用法

  1. Radio(
  2. value: "小钟",
  3. groupValue: _radioValue,
  4. activeColor: Colors.yellow[800],
  5. focusColor : Colors.green[300],
  6. visualDensity: VisualDensity(horizontal: 1),
  7. onChanged: (e){
  8. setState(() {
  9. _radioValue = e;
  10. });
  11. }
  12. ),

image.png

然而我们使用Radio的时候不单单需要给出选择的位置,而且还需要文本提示。

上面的话,只能在后面添加一个Text来实现文本提示。

RadioListTile 解决上述问题


基本属性

  1. const RadioListTile({
  2. Key key,
  3. @required this.value,
  4. @required this.groupValue,
  5. @required this.onChanged,
  6. this.activeColor,
  7. this.title, // 标题
  8. this.subtitle, // 标题下面显示的附加内容。
  9. this.isThreeLine = false, //此列表平铺是否用于显示三行文本。如果为false,则在副标题为空的情况下,列表平铺被视为只有一行,在副标题为非空的情况下,则视为有两行。
  10. this.dense,
  11. this.secondary,
  12. this.selected = false,
  13. this.controlAffinity = ListTileControlAffinity.platform,
  14. }) : assert(isThreeLine != null),
  15. assert(!isThreeLine || subtitle != null),
  16. assert(selected != null),
  17. assert(controlAffinity != null),
  18. super(key: key);

基本用法

  1. Flexible(
  2. child: RadioListTile(
  3. value: "小钟",
  4. groupValue: _radioValue,
  5. activeColor: Colors.yellow[800],
  6. title: Text("小钟"),
  7. subtitle: Text("小钟是一枚认真的程序员!"),
  8. isThreeLine: true,
  9. dense: false,
  10. secondary: IconButton(
  11. onPressed: (){},
  12. icon: Icon(IconData(0xe660, fontFamily : 'wz')),
  13. ),
  14. onChanged: (e){
  15. setState(() {
  16. _radioValue = e;
  17. });
  18. }
  19. )
  20. ),

image.png