Radio
image
屬性
- value radio 的取值
- groupValue radio 組的取值。value == groupValue 的時(shí)候?yàn)檫x中狀態(tài)。
- onChanged 取值變化時(shí)候的回調(diào)
- activeColor 選中時(shí)候的顏色
class RadioWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return new _RadioWidget();
}
}
class _RadioWidget extends State<RadioWidget> {
String _value = '';
@override
Widget build(BuildContext context) {
// TODO: implement build
return Column(
children: <Widget>[
Row(
children: <Widget>[
Radio(
value: 'a',
activeColor: Colors.blue,
groupValue: _value,
onChanged: (newValue) {
setState(() {
_value = newValue;
});
}
),
Text('開(kāi)')
],
),
Row(
children: <Widget>[
Radio(
value: 'b',
activeColor: Colors.blue,
groupValue: _value,
onChanged: (newValue) {
setState(() {
_value = newValue;
});
}
),
Text('關(guān)')
],
)
],
);
}
}
Checkbox
屬性
- value bool 類型 true 選中,false 不選中
- tristate 如果設(shè)置成 true,value 的值可以是 null
- activeColor 選中時(shí)候的背景顏色
- checkColor 選中時(shí)候的 Icon 顏色
- materialTapTargetSize 設(shè)置 tap 響應(yīng)大小
class CheckboxWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return new _CheckboxWidget();
}
}
class _CheckboxWidget extends State<CheckboxWidget> {
bool _value = false;
@override
Widget build(BuildContext context) {
// TODO: implement build
return Column(
children: <Widget>[
Row(
children: <Widget>[
Checkbox(
value: _value,
onChanged: (newValue) {
print('$newValue');
setState(() {
_value = newValue;
});
},
tristate: false,
activeColor: Colors.red,
checkColor: Colors.blue
),
],
),
],
);
}
}