-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathtd_icon_page.dart
153 lines (143 loc) · 4.92 KB
/
td_icon_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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../../base/example_widget.dart';
import '../annotation/demo.dart';
class TDIconPage extends StatefulWidget {
const TDIconPage({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _TDIconPageState();
}
class _TDIconPageState extends State<TDIconPage> {
bool showBorder = false;
dynamic iconList = [];
var isLoading = false;
@override
void initState() {
super.initState();
iconList = TDIcons.all.values;
}
@override
Widget build(BuildContext context) {
return ExamplePage(
title: tdTitle(),
desc: 'Icon 作为UI构成中重要的元素,一定程度上影响UI界面整体呈现出的风格。',
exampleCodeGroup: 'icon',
children: [
ExampleModule(
title: 'icon示例', children: [ExampleItem(desc: 'icon数量: ${iconList.length}', builder: _showAllIcons)])
]);
}
@Demo(group: 'icon')
Widget _showAllIcons(BuildContext context) {
return Container(
color: Colors.white,
alignment: Alignment.center,
child: Column(
children: [
Container(
padding: const EdgeInsets.only(left: 16),
alignment: Alignment.topLeft,
child: const Wrap(
children: [
TDText('筛选Icon请前往TDesign官网(长按网址可复制):'),
SelectableText('https://tdesign.tencent.com/vue/components/icon')
],
),
),
TDSearchBar(
action: '搜索',
onActionClick: (text) {
setState(() {
iconList = [];
isLoading = true;
});
Future.delayed(const Duration(milliseconds: 30), () {
var list = [];
TDIcons.all.forEach((key, value) {
if (value.name.contains(text)) {
list.add(value);
}
});
setState(() {
iconList = list;
isLoading = false;
});
});
},
onClearClick: (_) {
setState(() {
iconList = TDIcons.all.values;
});
},
),
Container(
child: TDButton(
text: showBorder ? '隐藏边框' : '显示边框',
shape: TDButtonShape.filled,
onTap: () {
setState(() {
showBorder = !showBorder;
});
},
),
margin: const EdgeInsets.only(bottom: 16),
),
Builder(builder: (context) {
if (iconList.isEmpty) {
return Container(
height: 300,
alignment: Alignment.center,
child: isLoading ? const TDText('加载中...') : const TDText('暂无内容'),
);
}
return SizedBox(
height: MediaQuery.of(context).size.height - 150,
child: ListView.builder(
itemCount: (iconList.length + 1) ~/ 2,
itemBuilder: (context,index){
var index1 = index ~/ 2;
var index2 = index1 + 1;
var iconData1 = iconList.elementAt(index1);
var iconData2;
if(iconList.length > index2){
iconData2 = iconList.elementAt(index2);
}
return Row(
children: [
SizedBox(
height: 100,
width: 175,
child: Column(
children: [
Container(
color: showBorder ? TDTheme.of(context).brandDisabledColor : Colors.transparent,
child: Icon(iconData1),
),
TDText(iconData1.name)
],
),
),
if (iconData2 != null)
SizedBox(
height: 100,
width: 175,
child: Column(
children: [
Container(
color: showBorder ? TDTheme.of(context).brandDisabledColor : Colors.transparent,
child: Icon(iconData2),
),
TDText(iconData2.name)
],
),
)
],
);
}),
);
})
],
),
);
}
}