forked from Tencent/tdesign-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtd_toast_page.dart
More file actions
336 lines (316 loc) · 9.44 KB
/
td_toast_page.dart
File metadata and controls
336 lines (316 loc) · 9.44 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
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/src/util/auto_size.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../../base/example_widget.dart';
import '../annotation/demo.dart';
class TDToastPage extends StatelessWidget {
const TDToastPage({super.key});
@override
Widget build(BuildContext context) {
return ExamplePage(
title: tdTitle(context),
desc: '用于轻量级反馈或提示,不会打断用户操作。',
exampleCodeGroup: 'toast',
children: [
ExampleModule(title: '组件类型', children: [
ExampleItem(desc: '纯文字', builder: _textToast),
ExampleItem(desc: '多行文字', builder: _multipleToast),
ExampleItem(desc: '带横向图标', builder: _horizontalIconToast),
ExampleItem(desc: '带竖向图标', builder: _verticalIconToast),
ExampleItem(desc: '加载状态', builder: _loadingToast),
ExampleItem(desc: '加载状态自定义', builder: _loadingCustomToast),
ExampleItem(desc: '加载状态(无文字)', builder: _loadingWithoutTextToast),
ExampleItem(desc: '停止加载', builder: _dismissLoadingToast),
ExampleItem(desc: '自定义纯文字', builder: _textCustomToast),
]),
ExampleModule(title: '组件状态', children: [
ExampleItem(desc: '成功提示', builder: _successToast),
ExampleItem(desc: '成功提示(竖向)', builder: _successVerticalToast),
ExampleItem(desc: '警告提示', builder: _warningToast),
ExampleItem(desc: '警告提示(竖向)', builder: _warningVerticalToast),
ExampleItem(desc: '失败提示', builder: _failToast),
ExampleItem(desc: '失败提示(竖向)', builder: _failVerticalToast),
])
],
test: [
ExampleItem(desc: '禁止滚动+点击', builder: _preventTapToast),
ExampleItem(desc: '自定义宽度+行数', builder: _customMultipleToast),
],
);
}
@Demo(group: 'toast')
Widget _textToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showText('轻提示文字内容', context: context);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '纯文字',
);
}
@Demo(group: 'toast')
Widget _textCustomToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showText(
'自定义纯文字',
context: context,
customWidget: Container(
width: 50,
height: 20,
child: const TDText('自定义纯文字'),
color: TDTheme.of(context).brandClickColor,
),
);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '纯文字',
);
}
@Demo(group: 'toast')
Widget _multipleToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showText('最多一行展示十个汉字宽度限制最多不超过三行文字', context: context);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '多行文字',
);
}
@Demo(group: 'toast')
Widget _horizontalIconToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showIconText(
'带横向图标',
icon: TDIcons.check_circle,
context: context,
);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '带横向图标',
);
}
@Demo(group: 'toast')
Widget _verticalIconToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showIconText(
'带竖向图标',
icon: TDIcons.check_circle,
direction: IconTextDirection.vertical,
context: context,
);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '带竖向图标',
);
}
@Demo(group: 'toast')
Widget _loadingToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showLoading(context: context);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '加载状态',
);
}
@Demo(group: 'toast')
Widget _loadingCustomToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showLoading(
context: context,
customWidget: Container(
width: 50,
height: 20,
child: const TDText('自定义加载'),
color: TDTheme.of(context).brandColor1,
),
);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '加载状态',
);
}
@Demo(group: 'toast')
Widget _loadingWithoutTextToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showLoadingWithoutText(context: context);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '加载状态(无文案)',
);
}
@Demo(group: 'toast')
Widget _dismissLoadingToast(BuildContext context) {
return const TDButton(
onTap: TDToast.dismissLoading,
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '停止加载',
);
}
@Demo(group: 'toast')
Widget _successToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showSuccess('成功文案', context: context);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '成功提示',
);
}
@Demo(group: 'toast')
Widget _successVerticalToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showSuccess(
'成功文案',
direction: IconTextDirection.vertical,
context: context,
);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '成功提示(竖向)',
);
}
@Demo(group: 'toast')
Widget _warningToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showWarning(
'警告文案',
direction: IconTextDirection.horizontal,
context: context,
);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '警告提示',
);
}
@Demo(group: 'toast')
Widget _warningVerticalToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showWarning(
'警告文案',
direction: IconTextDirection.vertical,
context: context,
);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '警告提示(竖向)',
);
}
@Demo(group: 'toast')
Widget _failToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showFail(
'失败文案',
direction: IconTextDirection.horizontal,
context: context,
);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '失败提示',
);
}
@Demo(group: 'toast')
Widget _failVerticalToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showFail(
'失败文案',
direction: IconTextDirection.vertical,
context: context,
);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '失败提示(竖向)',
);
}
@Demo(group: 'toast')
Widget _preventTapToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showText(
'轻提示文字内容',
context: context,
preventTap: true,
backgroundColor: Colors.black.withOpacity(0.7),
);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '禁止滚动+点击',
);
}
@Demo(group: 'toast')
Widget _customMultipleToast(BuildContext context) {
return TDButton(
onTap: () {
TDToast.showText(
'最多一行展示十个汉字宽度限制最多不超过三行文字最多一行展示十个汉字宽度限制最多不超过三行文字最多一行展示十个汉字宽度限制最多不超过三行文字最多一行展示十个汉字宽度限制最多不超过三行文字最多一行展示十个汉字宽度限制最多不超过三行文字最多一行展示十个汉字宽度限制最多不超过三行文字',
context: context,
constraints: BoxConstraints(maxWidth: 350.scale),
maxLines: 5,
);
},
size: TDButtonSize.large,
type: TDButtonType.outline,
theme: TDButtonTheme.primary,
isBlock: true,
text: '多行文字',
);
}
}