-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathtd_link_page.dart
181 lines (166 loc) · 5.65 KB
/
td_link_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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../annotation/demo.dart';
import '../base/example_widget.dart';
class TDLinkViewPage extends StatefulWidget {
const TDLinkViewPage({Key? key}) : super(key: key);
@override
_TDLinkViewPageState createState() => _TDLinkViewPageState();
}
class _TDLinkViewPageState extends State<TDLinkViewPage> {
@override
Widget build(BuildContext context) {
return ExamplePage(
backgroundColor: const Color(0xFFF0F2F5),
title: tdTitle(),
desc: '当功能使用图标即可表意清楚时,可使用纯图标悬浮按钮,例如:添加、发布。',
exampleCodeGroup: 'link',
children: [
ExampleModule(title: '组件类型', children: [
ExampleItem(desc: '基础文字链接', builder: _basicTypeBasic),
ExampleItem(desc: '下划线文字链接', builder: _withUnderline),
ExampleItem(desc: '前置图标文字链接', builder: _withPrefixIcon),
ExampleItem(desc: '后置图标文字链接', builder: _withSuffixIcon),
]),
ExampleModule(title: '组件状态', children: [
ExampleItem(desc: '不同主题', builder: _buildLinkStats),
ExampleItem(desc: '禁用状态', builder: _buildDisabledLinkStats)
]),
ExampleModule(
title: '组件样式',
children: [ExampleItem(desc: '链接尺寸', builder: _buildLinkSizes)]),
]);
}
@Demo(group: 'link')
Widget _basicTypeBasic(BuildContext context) {
return Container(
color: TDTheme.of(context).whiteColor1,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: _buildLinksWithType(TDLinkType.basic),
));
}
List<Widget> _buildLinksWithType(TDLinkType type) {
return [
TDLink(
label: '跳转链接',
style: TDLinkStyle.primary,
type: type,
size: TDLinkSize.small,
),
const SizedBox(
height: 48,
width: 80,
),
TDLink(
label: '跳转链接',
style: TDLinkStyle.defaultStyle,
type: type,
size: TDLinkSize.small,
),
const SizedBox(
height: 16,
),
];
}
@Demo(group: 'link')
Widget _withUnderline(BuildContext context) {
return Container(
color: TDTheme.of(context).whiteColor1,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: _buildLinksWithType(TDLinkType.withUnderline),
));
}
@Demo(group: 'link')
Widget _withSuffixIcon(BuildContext context) {
return Container(
color: TDTheme.of(context).whiteColor1,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: _buildLinksWithType(TDLinkType.withSuffixIcon),
));
}
@Demo(group: 'link')
Widget _withPrefixIcon(BuildContext context) {
return Container(
color: TDTheme.of(context).whiteColor1,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: _buildLinksWithType(TDLinkType.withPrefixIcon),
));
}
@Demo(group: 'link')
Widget _buildLinkStats(BuildContext context) {
return _buildLinkWithStyles(TDLinkState.normal);
}
@Demo(group: 'link')
Widget _buildDisabledLinkStats(BuildContext context) {
return _buildLinkWithStyles(TDLinkState.disabled);
}
Column _buildLinkWithStyles(TDLinkState state) {
return Column(
children: [
Container(
color: TDTheme.of(context).whiteColor1,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildLinkWithTypeAndState(TDLinkStyle.primary, state),
const SizedBox(height: 48, width: 50),
_buildLinkWithTypeAndState(TDLinkStyle.defaultStyle, state),
const SizedBox(height: 48, width: 50),
_buildLinkWithTypeAndState(TDLinkStyle.danger, state),
],
)),
const SizedBox(height: 16),
Container(
color: TDTheme.of(context).whiteColor1,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildLinkWithTypeAndState(TDLinkStyle.warning, state),
const SizedBox(height: 48, width: 50),
_buildLinkWithTypeAndState(TDLinkStyle.success, state),
],
)),
],
);
}
TDLink _buildLinkWithTypeAndState(TDLinkStyle style, TDLinkState state) {
return TDLink(
label: '跳转链接',
style: style,
state: state,
type: TDLinkType.withSuffixIcon,
size: TDLinkSize.small,
);
}
@Demo(group: 'link')
Widget _buildLinkSizes(BuildContext context) {
return Container(
color: TDTheme.of(context).whiteColor1,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildLinkWithSizeAndStyle(TDLinkStyle.primary, TDLinkSize.small),
const SizedBox(height: 48, width: 40),
_buildLinkWithSizeAndStyle(TDLinkStyle.primary, TDLinkSize.medium),
const SizedBox(height: 48, width: 40),
_buildLinkWithSizeAndStyle(TDLinkStyle.primary, TDLinkSize.large),
],
));
}
TDLink _buildLinkWithSizeAndStyle(TDLinkStyle style, TDLinkSize size) {
var s = size == TDLinkSize.small
? 'S'
: (size == TDLinkSize.medium ? 'M' : 'L');
return TDLink(
label: '$s号链接',
style: style,
state: TDLinkState.normal,
type: TDLinkType.withSuffixIcon,
size: size,
);
}
}