forked from Tencent/tdesign-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtd_skeleton_page.dart
More file actions
221 lines (206 loc) · 6.77 KB
/
td_skeleton_page.dart
File metadata and controls
221 lines (206 loc) · 6.77 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../../annotation/demo.dart';
import '../../base/example_widget.dart';
class TDSkeletonPage extends StatelessWidget {
const TDSkeletonPage({super.key});
@override
Widget build(BuildContext context) {
return ExamplePage(
title: tdTitle(context),
desc: '当网络较慢时,在页面真实数据加载之前,给用户展示出页面的大致结构。',
exampleCodeGroup: 'skeleton',
children: [
ExampleModule(
title: '类型',
children: [
ExampleItem(
desc: '头像骨架屏',
builder: _wrapper(_buildAvatarSkeleton),
methodName: '_buildAvatarSkeleton',
),
ExampleItem(
desc: '图片骨架屏',
builder: _wrapper(_buildImageSkeleton),
methodName: '_buildImageSkeleton',
),
ExampleItem(
desc: '文本骨架屏',
builder: _wrapper(_buildTextSkeleton, isFlexible: true),
methodName: '_buildTextSkeleton',
),
ExampleItem(
desc: '段落骨架屏',
builder: _wrapper(_buildParagraphSkeleton, isFlexible: true),
methodName: '_buildParagraphSkeleton',
),
ExampleItem(
desc: '单元格骨架屏',
builder: _wrapper(_buildCellSkeleton),
methodName: '_buildCellSkeleton',
),
ExampleItem(
desc: '宫格骨架屏',
builder: _wrapper(_buildGridSkeleton),
methodName: '_buildGridSkeleton',
),
ExampleItem(
desc: '图文组合骨架屏',
builder: _wrapper(_buildCombineSkeleton),
methodName: '_buildCombineSkeleton',
),
],
),
ExampleModule(
title: '组件动效',
children: [
ExampleItem(
desc: '渐变加载效果',
builder: _wrapper(_buildGradientSkeleton, isFlexible: true),
methodName: '_buildGradientSkeleton',
),
ExampleItem(
desc: '闪烁加载效果',
builder: _wrapper(_buildFlashedSkeleton, isFlexible: true),
methodName: '_buildFlashedSkeleton',
),
],
),
]);
}
Widget Function(BuildContext) _wrapper(
Function(BuildContext) builder, {
bool isFlexible = false,
}) =>
(context) => Container(
alignment: Alignment.topLeft,
padding: EdgeInsets.fromLTRB(
TDTheme.of(context).spacer16,
0,
TDTheme.of(context).spacer16,
0,
),
child: isFlexible
? Row(children: [builder(context)])
: builder(context),
);
@Demo(group: 'skeleton')
Widget _buildAvatarSkeleton(BuildContext context) {
return TDSkeleton(theme: TDSkeletonTheme.avatar);
}
@Demo(group: 'skeleton')
Widget _buildImageSkeleton(BuildContext context) {
return TDSkeleton(theme: TDSkeletonTheme.image);
}
@Demo(group: 'skeleton')
Widget _buildTextSkeleton(BuildContext context) {
return TDSkeleton(theme: TDSkeletonTheme.text);
}
@Demo(group: 'skeleton')
Widget _buildParagraphSkeleton(BuildContext context) {
return TDSkeleton(theme: TDSkeletonTheme.paragraph);
}
@Demo(group: 'skeleton')
Widget _buildCellSkeleton(BuildContext context) {
final rowColsAvatar = TDSkeleton(theme: TDSkeletonTheme.avatar);
final rowColsImage = TDSkeleton.fromRowCol(
rowCol: TDSkeletonRowCol(objects: const [
[TDSkeletonRowColObj.rect(width: 48, height: 48)]
]),
);
final rowColsContent = TDSkeleton.fromRowCol(
rowCol: TDSkeletonRowCol(
objects: const [
[TDSkeletonRowColObj(), TDSkeletonRowColObj.spacer(flex: 1)],
[TDSkeletonRowColObj()]
],
),
);
return Column(
// spacing: 16,
children: [
Row(
// spacing: 12,
children: [
rowColsAvatar,
const SizedBox(width: 12),
rowColsContent,
],
),
const SizedBox(height: 16),
Row(
// spacing: 12,
children: [
rowColsImage,
const SizedBox(width: 12),
rowColsContent,
],
),
],
);
}
@Demo(group: 'skeleton')
Widget _buildGridSkeleton(BuildContext context) {
return Row(
// spacing: 16,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: List.generate(5, (index) {
return TDSkeleton.fromRowCol(
rowCol: TDSkeletonRowCol(objects: const [
[TDSkeletonRowColObj.rect(width: 48, height: 48, flex: null)],
[TDSkeletonRowColObj.text(width: 48, flex: null)],
]),
);
}),
);
}
@Demo(group: 'skeleton')
Widget _buildCombineSkeleton(BuildContext context) {
final rowCols = Flexible(
child: LayoutBuilder(
builder: (context, constraints) => Row(children: [
TDSkeleton.fromRowCol(
rowCol: TDSkeletonRowCol(
objects: [
[
TDSkeletonRowColObj(
width: constraints.maxWidth,
height: constraints.maxWidth,
flex: null,
style: TDSkeletonRowColObjStyle(
borderRadius: (context) =>
TDTheme.of(context).radiusExtraLarge))
],
[TDSkeletonRowColObj.text(width: constraints.maxWidth)],
const [
TDSkeletonRowColObj.text(),
TDSkeletonRowColObj.spacer(flex: 1),
],
],
),
)
])));
return Row(
// spacing: TDTheme.of(context).spacer16,
children: [
rowCols,
SizedBox(width: TDTheme.of(context).spacer16),
rowCols,
],
);
}
@Demo(group: 'skeleton')
Widget _buildGradientSkeleton(BuildContext context) {
return TDSkeleton(
animation: TDSkeletonAnimation.gradient,
theme: TDSkeletonTheme.paragraph,
);
}
@Demo(group: 'skeleton')
Widget _buildFlashedSkeleton(BuildContext context) {
return TDSkeleton(
animation: TDSkeletonAnimation.flashed,
theme: TDSkeletonTheme.paragraph,
);
}
}