-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathtd_tree_select_page.dart
121 lines (103 loc) · 3.2 KB
/
td_tree_select_page.dart
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import 'package:flutter/cupertino.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../annotation/demo.dart';
import '../base/example_widget.dart';
class TDTreeSelectPage extends StatefulWidget {
const TDTreeSelectPage({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _TDTreeSelectPageState();
}
class _TDTreeSelectPageState extends State<TDTreeSelectPage> {
String? inputText;
List<dynamic> values1 = [
1,
11,
];
List<dynamic> values2 = [
1,
[11, 12, 13],
];
List<dynamic> values3 = [1, 11, 111];
@override
Widget build(BuildContext context) {
return ExamplePage(
title: tdTitle(),
desc: '适用于选择树形的数据结构',
exampleCodeGroup: 'tree',
backgroundColor: TDTheme.of(context).grayColor2,
children: [
ExampleModule(
title: '组件类型',
children: [
ExampleItem(desc: '基础树形选择', builder: _buildDefaultTreeSelect),
ExampleItem(desc: '多选树形选择', builder: _buildMultipleTreeSelect),
],
),
ExampleModule(
title: '组件状态',
children: [
ExampleItem(desc: '三级树形选择', builder: _buildThirdTreeSelect),
],
),
]);
}
@Demo(group: 'tree')
Widget _buildDefaultTreeSelect(BuildContext context) {
var options = <TDSelectOption>[];
for (var i = 1; i <= 10; i++) {
options.add(TDSelectOption(label: '选项$i', value: i, children: []));
for (var j = 1; j <= 10; j++) {
options[i - 1].children.add(
TDSelectOption(label: '选项$i.$j', value: i * 10 + j, children: []));
}
}
return TDTreeSelect(
options: options,
defaultValue: values1,
onChange: (val, level) {
print('$val, $level');
},
);
}
@Demo(group: 'tree')
Widget _buildMultipleTreeSelect(BuildContext context) {
var options = <TDSelectOption>[];
for (var i = 1; i <= 10; i++) {
options.add(TDSelectOption(label: '选项$i', value: i, children: []));
for (var j = 1; j <= 10; j++) {
options[i - 1].children.add(
TDSelectOption(label: '选项$i.$j', value: i * 10 + j, children: []));
}
}
return TDTreeSelect(
options: options,
defaultValue: values2,
multiple: true,
onChange: (val, level) {
print('$val, $level');
},
);
}
@Demo(group: 'tree')
Widget _buildThirdTreeSelect(BuildContext context) {
var options = <TDSelectOption>[];
for (var i = 1; i <= 10; i++) {
options.add(TDSelectOption(label: '选项$i', value: i, children: []));
for (var j = 1; j <= 10; j++) {
options[i - 1].children.add(
TDSelectOption(label: '选项$i.$j', value: i * 10 + j, children: []));
for (var k = 1; k <= 10; k++) {
options[i - 1].children[j - 1].children.add(
TDSelectOption(label: '选项$i.$j.$k', value: i * 100 + j * 10 + k));
}
}
}
return TDTreeSelect(
options: options,
defaultValue: values3,
onChange: (val, level) {
print('$val, $level');
},
);
}
}