forked from Tencent/tdesign-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtd_time_counter_page.dart
More file actions
467 lines (441 loc) · 13.5 KB
/
td_time_counter_page.dart
File metadata and controls
467 lines (441 loc) · 13.5 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../../base/example_widget.dart';
import '../annotation/demo.dart';
class TDTimeCounterPage extends StatelessWidget {
const TDTimeCounterPage({super.key});
@override
Widget build(BuildContext context) {
return ExamplePage(
title: tdTitle(context),
desc: '用于实时展示计时数值。',
exampleCodeGroup: 'timeCounter',
children: [
const ExampleModule(title: '组件类型', children: [
ExampleItem(desc: '时分秒', builder: _buildSimple),
ExampleItem(desc: '带毫秒', builder: _buildMillisecondSimple),
ExampleItem(desc: '正向计时', builder: _buildUpSimple),
ExampleItem(desc: '带方形底', builder: _buildSquareSimple),
ExampleItem(desc: '带圆形底', builder: _buildRoundSimple),
ExampleItem(desc: '带单位', builder: _buildUnitSimple),
ExampleItem(desc: '无底色带单位', builder: _buildCustomUnitSimple),
]),
ExampleModule(title: '组件尺寸', children: [
ExampleItem(
ignoreCode: true,
desc: '纯数字',
builder: (BuildContext context) {
return const Wrap(
direction: Axis.vertical,
spacing: 16,
children: [
Row(
// spacing: 40,
children: [
Text('小'),
SizedBox(width: 40),
CodeWrapper(builder: _buildSmallSize),
],
),
Row(
// spacing: 40,
children: [
Text('中'),
SizedBox(width: 40),
CodeWrapper(builder: _buildMediumSize)
],
),
Row(
// spacing: 40,
children: [
Text('大'),
SizedBox(width: 40),
CodeWrapper(builder: _buildLargeSize),
],
),
],
);
},
),
ExampleItem(
ignoreCode: true,
desc: '带方形底',
builder: (BuildContext context) {
return const Wrap(
direction: Axis.vertical,
spacing: 16,
children: [
Row(
// spacing: 40,
children: [
Text('小'),
SizedBox(width: 40),
CodeWrapper(builder: _buildSquareSmallSize),
],
),
Row(
// spacing: 40,
children: [
Text('中'),
SizedBox(width: 40),
CodeWrapper(builder: _buildSquareMediumSize),
],
),
Row(
// spacing: 40,
children: [
Text('大'),
SizedBox(width: 40),
CodeWrapper(builder: _buildSquareLargeSize),
],
),
]);
},
),
ExampleItem(
ignoreCode: true,
desc: '带圆形底',
builder: (BuildContext context) {
return const Wrap(
direction: Axis.vertical,
spacing: 16,
children: [
Row(
// spacing: 40,
children: [
Text('小'),
SizedBox(width: 40),
CodeWrapper(builder: _buildRoundSmallSize),
],
),
Row(
// spacing: 40,
children: [
Text('中'),
SizedBox(width: 40),
CodeWrapper(builder: _buildRoundMediumSize),
],
),
Row(
// spacing: 40,
children: [
Text('大'),
SizedBox(width: 40),
CodeWrapper(builder: _buildRoundLargeSize),
],
),
]);
},
),
ExampleItem(
ignoreCode: true,
desc: '带单位',
builder: (BuildContext context) {
return const Wrap(
direction: Axis.vertical,
spacing: 16,
children: [
Row(
// spacing: 40,
children: [
Text('小'),
SizedBox(width: 40),
CodeWrapper(builder: _buildUnitSmallSize),
],
),
Row(
// spacing: 40,
children: [
Text('中'),
SizedBox(width: 40),
CodeWrapper(builder: _buildUnitMediumSize),
],
),
Row(
// spacing: 40,
children: [
Text('大'),
SizedBox(width: 40),
CodeWrapper(builder: _buildUnitLargeSize),
],
),
]);
},
),
ExampleItem(
ignoreCode: true,
desc: '无底色带单位',
builder: (BuildContext context) {
return const Wrap(
spacing: 8,
direction: Axis.vertical,
children: [
Row(
// spacing: 40,
children: [
Text('小'),
SizedBox(width: 40),
CodeWrapper(builder: _buildCustomUnitSmallSize),
],
),
Row(
// spacing: 40,
children: [
Text('中'),
SizedBox(width: 40),
CodeWrapper(builder: _buildCustomUnitMediumSize),
],
),
Row(
// spacing: 40,
children: [
Text('大'),
SizedBox(width: 40),
CodeWrapper(builder: _buildCustomUnitLargeSize),
],
),
]);
},
),
]),
],
test: const [
ExampleItem(desc: '控制倒计时', builder: _buildControl),
ExampleItem(desc: '自定义显示位数', builder: _buildCustomNum),
],
);
}
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildSimple(BuildContext context) {
return const TDTimeCounter(time: 60 * 60 * 1000);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildMillisecondSimple(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
millisecond: true,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildUpSimple(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
millisecond: true,
direction: TDTimeCounterDirection.up,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildSquareSimple(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
theme: TDTimeCounterTheme.square,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildRoundSimple(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
theme: TDTimeCounterTheme.round,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildUnitSimple(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
theme: TDTimeCounterTheme.square,
splitWithUnit: true,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildCustomUnitSimple(BuildContext context) {
var style = TDTimeCounterStyle.generateStyle(context);
style.timeColor = TDTheme.of(context).errorNormalColor;
return TDTimeCounter(
time: 60 * 60 * 1000,
splitWithUnit: true,
style: style,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildSmallSize(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
size: TDTimeCounterSize.small,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildMediumSize(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
size: TDTimeCounterSize.medium,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildLargeSize(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
size: TDTimeCounterSize.large,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildSquareSmallSize(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
size: TDTimeCounterSize.small,
theme: TDTimeCounterTheme.square,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildSquareMediumSize(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
size: TDTimeCounterSize.medium,
theme: TDTimeCounterTheme.square,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildSquareLargeSize(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
size: TDTimeCounterSize.large,
theme: TDTimeCounterTheme.square,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildRoundSmallSize(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
size: TDTimeCounterSize.small,
theme: TDTimeCounterTheme.round,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildRoundMediumSize(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
size: TDTimeCounterSize.medium,
theme: TDTimeCounterTheme.round,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildRoundLargeSize(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
size: TDTimeCounterSize.large,
theme: TDTimeCounterTheme.round,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildUnitSmallSize(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
size: TDTimeCounterSize.small,
theme: TDTimeCounterTheme.square,
splitWithUnit: true,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildUnitMediumSize(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
size: TDTimeCounterSize.medium,
theme: TDTimeCounterTheme.square,
splitWithUnit: true,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildUnitLargeSize(BuildContext context) {
return const TDTimeCounter(
time: 60 * 60 * 1000,
size: TDTimeCounterSize.large,
theme: TDTimeCounterTheme.square,
splitWithUnit: true,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildCustomUnitSmallSize(BuildContext context) {
var style =
TDTimeCounterStyle.generateStyle(context, size: TDTimeCounterSize.small);
style.timeColor = TDTheme.of(context).errorNormalColor;
return TDTimeCounter(
time: 60 * 60 * 1000,
splitWithUnit: true,
style: style,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildCustomUnitMediumSize(BuildContext context) {
var style =
TDTimeCounterStyle.generateStyle(context, size: TDTimeCounterSize.medium);
style.timeColor = TDTheme.of(context).errorNormalColor;
return TDTimeCounter(
time: 60 * 60 * 1000,
splitWithUnit: true,
style: style,
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildCustomUnitLargeSize(BuildContext context) {
var style =
TDTimeCounterStyle.generateStyle(context, size: TDTimeCounterSize.large);
style.timeColor = TDTheme.of(context).errorNormalColor;
return TDTimeCounter(
time: 60 * 60 * 1000,
splitWithUnit: true,
style: style,
);
}
@Demo(group: 'timeCounter')
Widget _buildControl(BuildContext context) {
var controller = TDTimeCounterController();
return Wrap(
direction: Axis.vertical,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 8,
children: [
TDTimeCounter(
time: 60 * 60 * 1000,
controller: controller,
// autoStart: false,
),
Wrap(
spacing: 8,
children: [
TDButton(
text: '开始',
theme: TDButtonTheme.primary,
onTap: () => controller.start(),
),
TDButton(
text: '结束',
theme: TDButtonTheme.primary,
onTap: () => controller.reset(0),
),
TDButton(
text: '重置',
theme: TDButtonTheme.primary,
onTap: () => controller.reset(),
),
TDButton(
text: '暂停',
theme: TDButtonTheme.primary,
onTap: () => controller.pause(),
),
TDButton(
text: '继续',
theme: TDButtonTheme.primary,
onTap: () => controller.resume(),
),
],
)
],
);
}
@Demo(group: 'timeCounter')
TDTimeCounter _buildCustomNum(BuildContext context) {
return const TDTimeCounter(
time: 2000 * 60 * 1000,
format: 'mmmmmmm分sss秒',
);
}