-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathtd_swipe_cell_page.dart
353 lines (343 loc) · 10.4 KB
/
td_swipe_cell_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
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
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../annotation/demo.dart';
import '../base/example_widget.dart';
class TDSwipeCellPage extends StatelessWidget {
const TDSwipeCellPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ExamplePage(
title: tdTitle(context),
exampleCodeGroup: 'swipecell',
desc: '用于承载列表中的更多操作,通过左右滑动来展示,按钮的宽度固定高度根据列表高度而变化。',
children: [
ExampleModule(
title: '组件类型',
children: [
ExampleItem(
desc: '左滑单操作',
builder: _buildSwiperCell,
),
ExampleItem(
desc: '左滑双操作',
builder: _buildSwiperMuliCell,
),
ExampleItem(
desc: '左滑三操作',
builder: _buildSwiper3Cell,
),
ExampleItem(
desc: '右滑单操作',
builder: _buildSwiperRightCell,
),
ExampleItem(
desc: '左右滑操作',
builder: _buildSwiperRightLeftCell,
),
ExampleItem(
desc: '带图标的滑动操作',
builder: _buildSwiperIconCell,
),
ExampleItem(
desc: '带二次确认的操作',
builder: _buildSwiperConfirmCell,
),
],
),
],
test: const [],
);
}
@Demo(group: 'swipecell')
Widget _buildSwiperCell(BuildContext context) {
// 屏幕宽度
var screenWidth = MediaQuery.of(context).size.width;
var list = [
{'id': '1', 'title': '左滑操作', 'note': '辅助信息', 'description': ''},
{'id': '2', 'title': '左滑操作', 'note': '辅助信息', 'description': '一段很长很长的内容文字'},
];
final cellLength = ValueNotifier<int>(list.length);
return ValueListenableBuilder(
valueListenable: cellLength,
builder: (BuildContext context, value, Widget? child) {
return TDCellGroup(
cells: list.map((e) => TDCell(title: e['title'], note: e['note'], description: e['description'])).toList(),
builder: (context, cell, index) {
return TDSwipeCell(
slidableKey: ValueKey(list[index]['id']),
groupTag: 'test',
onChange: (direction, open) {
print('打开方向:$direction');
print('打开转态$open');
},
right: TDSwipeCellPanel(
extentRatio: 60 / screenWidth,
// dragDismissible: true,
onDismissed: (context) {
list.removeAt(index);
cellLength.value = list.length;
},
children: [
TDSwipeCellAction(
backgroundColor: TDTheme.of(context).errorColor6,
label: '删除',
onPressed: (context) {
print('点击action');
print(TDSwipeCell.of(context));
print(TDSwipeCellInherited.of(context)?.controller);
list.removeAt(index);
cellLength.value = list.length;
},
),
],
),
cell: cell,
);
},
);
},
);
}
@Demo(group: 'swipecell')
Widget _buildSwiperMuliCell(BuildContext context) {
// 屏幕宽度
var screenWidth = MediaQuery.of(context).size.width;
return TDSwipeCell(
groupTag: 'test',
right: TDSwipeCellPanel(
extentRatio: 120 / screenWidth,
children: [
TDSwipeCellAction(
flex: 60,
backgroundColor: TDTheme.of(context).warningColor4,
label: '编辑',
),
TDSwipeCellAction(
flex: 60,
backgroundColor: TDTheme.of(context).errorColor6,
label: '删除',
),
],
),
cell: const TDCell(
title: '左滑操作',
note: '辅助信息',
),
);
}
@Demo(group: 'swipecell')
Widget _buildSwiper3Cell(BuildContext context) {
// 屏幕宽度
var screenWidth = MediaQuery.of(context).size.width;
return TDSwipeCell(
groupTag: 'test',
right: TDSwipeCellPanel(
extentRatio: 180 / screenWidth,
children: [
TDSwipeCellAction(
flex: 60,
backgroundColor: TDTheme.of(context).brandColor7,
label: '保存',
),
TDSwipeCellAction(
flex: 60,
backgroundColor: TDTheme.of(context).warningColor4,
label: '编辑',
),
TDSwipeCellAction(
flex: 60,
backgroundColor: TDTheme.of(context).errorColor6,
label: '删除',
),
],
),
cell: const TDCell(
title: '左滑操作',
note: '辅助信息',
),
);
}
@Demo(group: 'swipecell')
Widget _buildSwiperRightCell(BuildContext context) {
// 屏幕宽度
var screenWidth = MediaQuery.of(context).size.width;
return TDSwipeCell(
groupTag: 'test',
left: TDSwipeCellPanel(
extentRatio: 60 / screenWidth,
children: [
TDSwipeCellAction(
backgroundColor: TDTheme.of(context).brandColor7,
label: '选择',
),
],
),
cell: const TDCell(
title: '右滑操作',
note: '辅助信息',
),
);
}
@Demo(group: 'swipecell')
Widget _buildSwiperRightLeftCell(BuildContext context) {
// 屏幕宽度
var screenWidth = MediaQuery.of(context).size.width;
return TDSwipeCell(
groupTag: 'test',
left: TDSwipeCellPanel(
extentRatio: 60 / screenWidth,
children: [
TDSwipeCellAction(
backgroundColor: TDTheme.of(context).brandColor7,
label: '选择',
),
],
),
right: TDSwipeCellPanel(
extentRatio: 120 / screenWidth,
children: [
TDSwipeCellAction(
flex: 60,
backgroundColor: TDTheme.of(context).warningColor4,
label: '编辑',
),
TDSwipeCellAction(
flex: 60,
backgroundColor: TDTheme.of(context).errorColor6,
label: '删除',
),
],
),
cell: const TDCell(
title: '左右滑操作',
note: '辅助信息',
),
);
}
@Demo(group: 'swipecell')
Widget _buildSwiperIconCell(BuildContext context) {
// 屏幕宽度
var screenWidth = MediaQuery.of(context).size.width;
return ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: 3,
itemBuilder: (context, index) {
if (index == 0) {
return TDSwipeCell(
groupTag: 'test',
right: TDSwipeCellPanel(
extentRatio: (80 + 80) / screenWidth,
children: [
TDSwipeCellAction(
flex: 80,
backgroundColor: TDTheme.of(context).warningColor4,
icon: TDIcons.edit,
label: '编辑',
),
TDSwipeCellAction(
flex: 80,
backgroundColor: TDTheme.of(context).errorColor6,
icon: TDIcons.delete,
label: '删除',
),
],
),
cell: const TDCell(
title: '右滑操作',
note: '辅助信息',
),
);
} else if (index == 1) {
return TDSwipeCell(
groupTag: 'test',
right: TDSwipeCellPanel(
extentRatio: 120 / screenWidth,
children: [
TDSwipeCellAction(
flex: 60,
backgroundColor: TDTheme.of(context).warningColor4,
icon: TDIcons.edit,
),
TDSwipeCellAction(
flex: 60,
backgroundColor: TDTheme.of(context).errorColor6,
icon: TDIcons.delete,
),
],
),
cell: const TDCell(
title: '右滑操作',
note: '辅助信息',
),
);
} else {
return TDSwipeCell(
groupTag: 'test',
right: TDSwipeCellPanel(
extentRatio: 120 / screenWidth,
children: [
TDSwipeCellAction(
flex: 60,
backgroundColor: TDTheme.of(context).warningColor4,
direction: Axis.vertical,
icon: TDIcons.edit,
label: '编辑',
),
TDSwipeCellAction(
flex: 60,
backgroundColor: TDTheme.of(context).errorColor6,
direction: Axis.vertical,
icon: TDIcons.delete,
label: '删除',
),
],
),
cell: const TDCell(
title: '右滑操作',
note: '辅助信息',
description: '一段很长很长的内容文字',
),
);
}
},
separatorBuilder: (context, index) {
return const SizedBox(height: 24);
},
);
}
@Demo(group: 'swipecell')
Widget _buildSwiperConfirmCell(BuildContext context) {
// 屏幕宽度
var screenWidth = MediaQuery.of(context).size.width;
return TDSwipeCell(
groupTag: 'test',
right: TDSwipeCellPanel(
extentRatio: (60 + 60) / screenWidth,
children: [
TDSwipeCellAction(
flex: 60,
backgroundColor: TDTheme.of(context).warningColor4,
label: '编辑',
),
TDSwipeCellAction(
flex: 60,
backgroundColor: TDTheme.of(context).errorColor6,
label: '删除',
),
],
confirms: [
TDSwipeCellAction(
backgroundColor: TDTheme.of(context).errorColor6,
label: '确认删除',
confirmIndex: const [1],
),
],
),
cell: const TDCell(
title: '右滑操作',
note: '辅助信息',
),
);
}
}