From 0f31be6fe6ccd22d8dd5b3e4fafa532b4e57b236 Mon Sep 17 00:00:00 2001 From: li_eh_chao <470360046@qq.com> Date: Thu, 30 Oct 2025 10:34:50 +0800 Subject: [PATCH] =?UTF-8?q?add:td=5Fupload=E5=A2=9E=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E4=B8=8A=E4=BC=A0=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/lib/page/td_upload_page.dart | 27 +++++++++++++++++++ .../lib/src/components/upload/td_upload.dart | 12 +++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tdesign-component/example/lib/page/td_upload_page.dart b/tdesign-component/example/lib/page/td_upload_page.dart index a84354018..69015dcea 100644 --- a/tdesign-component/example/lib/page/td_upload_page.dart +++ b/tdesign-component/example/lib/page/td_upload_page.dart @@ -54,6 +54,16 @@ class TDUploadState extends State { remotePath: 'https://tdesign.gtimg.com/demo/images/example4.png'), ]; final List files6 = []; + final List files7 = []; + + void onUploadTap() { + print('点击上传'); + setState(() { + files7.add(TDUploadFile( + key: files7.length + 1, + remotePath: 'https://tdesign.gtimg.com/demo/images/example1.png')); + }); + } void onValueChanged(List fileList, List value, TDUploadType event) { @@ -103,6 +113,7 @@ class TDUploadState extends State { ExampleItem(desc: '单选上传', builder: _uploadSingle), ExampleItem(desc: '单选上传(替换)', builder: _uploadSingleWithReplace), ExampleItem(desc: '多选上传', builder: _uploadMultiple), + ExampleItem(desc: '自定义upload按钮事件', builder: _uploadTap), ], ), ExampleModule( @@ -190,6 +201,22 @@ class TDUploadState extends State { )); } + @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('上传图片', diff --git a/tdesign-component/lib/src/components/upload/td_upload.dart b/tdesign-component/lib/src/components/upload/td_upload.dart index 011b5d63d..86a1716e2 100644 --- a/tdesign-component/lib/src/components/upload/td_upload.dart +++ b/tdesign-component/lib/src/components/upload/td_upload.dart @@ -87,6 +87,7 @@ class TDUpload extends StatefulWidget { this.wrapSpacing, this.wrapRunSpacing, this.wrapAlignment, + this.onUploadTap }) : super(key: key); /// 控制展示的文件列表 @@ -146,6 +147,9 @@ class TDUpload extends StatefulWidget { /// 多图对齐方式 final WrapAlignment? wrapAlignment; + ///自定义upload按钮事件 + final VoidCallback? onUploadTap; + @override State createState() => _TDUploadState(); } @@ -331,8 +335,12 @@ class _TDUploadState extends State { 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); + } }), ); }