Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tdesign-component/example/lib/page/td_upload_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ class TDUploadState extends State<TDUploadPage> {
remotePath: 'https://tdesign.gtimg.com/demo/images/example4.png'),
];
final List<TDUploadFile> files6 = [];
final List<TDUploadFile> files7 = [];

void onUploadTap() {
print('点击上传');
setState(() {
files7.add(TDUploadFile(
key: files7.length + 1,
remotePath: 'https://tdesign.gtimg.com/demo/images/example1.png'));
});
}

void onValueChanged(List<TDUploadFile> fileList, List<TDUploadFile> value,
TDUploadType event) {
Expand Down Expand Up @@ -103,6 +113,7 @@ class TDUploadState extends State<TDUploadPage> {
ExampleItem(desc: '单选上传', builder: _uploadSingle),
ExampleItem(desc: '单选上传(替换)', builder: _uploadSingleWithReplace),
ExampleItem(desc: '多选上传', builder: _uploadMultiple),
ExampleItem(desc: '自定义upload按钮事件', builder: _uploadTap),
],
),
ExampleModule(
Expand Down Expand Up @@ -190,6 +201,22 @@ class TDUploadState extends State<TDUploadPage> {
));
}

@Demo(group: 'upload')
Widget _uploadTap(BuildContext context) {
return wrapDemoContainer('自定义upload按钮事件',
child: TDUpload(
files: files7,
multiple: true,
max: 9,
onUploadTap: onUploadTap,
onClick: onClick,
onCancel: onCancel,
onError: print,
onValidate: print,
onChange: ((files, type) => onValueChanged(files7, files, type)),
));
}

@Demo(group: 'upload')
Widget _uploadLoading(BuildContext context) {
return wrapDemoContainer('上传图片',
Expand Down
12 changes: 10 additions & 2 deletions tdesign-component/lib/src/components/upload/td_upload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class TDUpload extends StatefulWidget {
this.wrapSpacing,
this.wrapRunSpacing,
this.wrapAlignment,
this.onUploadTap
}) : super(key: key);

/// 控制展示的文件列表
Expand Down Expand Up @@ -146,6 +147,9 @@ class TDUpload extends StatefulWidget {
/// 多图对齐方式
final WrapAlignment? wrapAlignment;

///自定义upload按钮事件
final VoidCallback? onUploadTap;

@override
State<TDUpload> createState() => _TDUploadState();
}
Expand Down Expand Up @@ -331,8 +335,12 @@ class _TDUploadState extends State<TDUpload> {
if (widget.disabled!) {
return;
}
final files = await getMediaFromPicker(widget.multiple);
extractImageList(files);
if (widget.onUploadTap != null) {
widget.onUploadTap!();
} else {
final files = await getMediaFromPicker(widget.multiple);
extractImageList(files);
}
}),
);
}
Expand Down