Flutter Widget之Radio

Widget:https://flutter.io/docs/development/ui/widgets
Radio:https://docs.flutter.io/flutter/material/Radio-class.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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;
});
}
}

Flutter Widget Radio

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :