Flutter Widget之Radio
Widget:https://flutter.io/docs/development/ui/widgets
Radio:https://docs.flutter.io/flutter/material/Radio-class.html
import 'package:flutter/material.dart';
class RadioButtonDemoPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new _RadioButtonDemoPageState();
}
}
class _RadioButtonDemoPageState extends State<RadioButtonDemoPage> {
int groupValue = 1;
String sGroupValue = '';
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text('RadioButton Demo'),
),
body: new Column(
//mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Radio(value: 0, groupValue: 0, onChanged: null),
//onChanged为null表示按钮不可用
new Radio(
value: 1,
groupValue: groupValue, //当value和groupValue一致的时候则选中
activeColor: Colors.red,
onChanged: (T) {
updateGroupValue(T);
}),
new Radio(
value: 2,
groupValue: groupValue,
onChanged: (T) {
updateGroupValue(T);
}),
new Radio(
value: 3,
groupValue: groupValue,
onChanged: (T) {
updateGroupValue(T);
}),
new RadioListTile(
value: 'Joe.Ye',
groupValue: sGroupValue,
title: new Text('Joe.Ye'),
onChanged: (T) {
updateStringGroupValue(T);
}),
new RadioListTile(
value: 'Android',
groupValue: sGroupValue,
title: new Text('Android'),
secondary: const Icon(Icons.favorite),
onChanged: (T) {
updateStringGroupValue(T);
}),
new RadioListTile(
value: 'iOS',
groupValue: sGroupValue,
title: new Text('iOS'),
onChanged: (T) {
updateStringGroupValue(T);
}),
],
),
);
}
void updateGroupValue(int v) {
setState(() {
groupValue = v;
});
}
void updateStringGroupValue(String v) {
setState(() {
sGroupValue = v;
});
}
}
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/16/flutter-widget-radio/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
打赏
海报
Flutter Widget之Radio
Widget:https://flutter.io/docs/development/ui/widgets
Radio:https://docs.flutter.io/flutter/material/Radio-class.html
import 'package……
文章目录
关闭
共有 0 条评论