Skip to content

Commit

Permalink
添加Upload方法
Browse files Browse the repository at this point in the history
  • Loading branch information
Luozf12345 committed Dec 10, 2024
1 parent 69bebb1 commit 0c17ab1
Show file tree
Hide file tree
Showing 10 changed files with 933 additions and 59 deletions.
10 changes: 8 additions & 2 deletions tdesign-component/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
PODS:
- Flutter (1.0.0)
- image_picker_ios (0.0.1):
- Flutter
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS

DEPENDENCIES:
- Flutter (from `Flutter`)
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)

EXTERNAL SOURCES:
Flutter:
:path: Flutter
image_picker_ios:
:path: ".symlinks/plugins/image_picker_ios/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"

SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
image_picker_ios: b545a5f16c0fa88e3ecbbce3ed4de45567a8ec18
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943

PODFILE CHECKSUM: cf0c950f7e9a456b4e325f5b8fc0f98906a3705a

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
EF2485925A6014C2D38ED73D /* [CP] Copy Pods Resources */,
BDA91D8CAA844B388F3140CD /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -169,7 +169,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -264,7 +264,7 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
};
EF2485925A6014C2D38ED73D /* [CP] Copy Pods Resources */ = {
BDA91D8CAA844B388F3140CD /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions tdesign-component/example/lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import 'page/td_theme_page.dart';
import 'page/td_time_counter_page.dart';
import 'page/td_toast_page.dart';
import 'page/td_tree_select_page.dart';
import 'page/td_upload_page.dart';
import 'page/todo_page.dart';

PageBuilder _wrapInheritedTheme(WidgetBuilder builder) {
Expand Down Expand Up @@ -151,8 +152,7 @@ Map<String, List<ExamplePageModel>> exampleMap = {
ExamplePageModel(
text: 'Upload 上传',
name: 'upload',
isTodo: true,
pageBuilder: _wrapInheritedTheme((context) => const TodoPage())),
pageBuilder: _wrapInheritedTheme((context) => const TDUploadPage())),
],
'数据展示': [
ExamplePageModel(
Expand Down
202 changes: 202 additions & 0 deletions tdesign-component/example/lib/page/td_upload_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import '../annotation/demo.dart';
import '../base/example_widget.dart';

class TDUploadPage extends StatefulWidget {
const TDUploadPage({Key? key}) : super(key: key);

@override
State<StatefulWidget> createState() => TDUploadState();
}

class TDUploadState extends State<TDUploadPage> {
final List<TDUploadFile> files1 = [];
final List<TDUploadFile> files2 = [
TDUploadFile(
key: 1,
remotePath:
'https://tdesign.gtimg.com/miniprogram/images/example4.png'),
TDUploadFile(
key: 2,
remotePath:
'https://tdesign.gtimg.com/miniprogram/images/example6.png'),
TDUploadFile(
key: 3,
remotePath:
'https://tdesign.gtimg.com/miniprogram/images/example5.png'),
];
final List<TDUploadFile> files3 = [
TDUploadFile(
key: 1,
status: TDUploadFileStatus.loading,
loadingText: '上传中...',
remotePath:
'https://tdesign.gtimg.com/miniprogram/images/example5.png'),
TDUploadFile(
key: 2,
status: TDUploadFileStatus.loading,
progress: 68,
remotePath:
'https://tdesign.gtimg.com/miniprogram/images/example4.png'),
];
final List<TDUploadFile> files4 = [
TDUploadFile(
key: 1,
status: TDUploadFileStatus.retry,
retryText: '重新上传',
remotePath:
'https://tdesign.gtimg.com/miniprogram/images/example4.png'),
];
final List<TDUploadFile> files5 = [
TDUploadFile(
key: 1,
status: TDUploadFileStatus.error,
errorText: '上传失败',
remotePath:
'https://tdesign.gtimg.com/miniprogram/images/example4.png'),
];

void onVaueChanged(List<TDUploadFile> fileList, List<TDUploadFile> value,
TDUploadType event) {
switch (event) {
case TDUploadType.add:
setState(() {
fileList.addAll(value);
});
break;
case TDUploadType.remove:
setState(() {
fileList.removeWhere((element) => element.key == value[0].key);
});
break;
}
}

void onClick(int key) {
print('点击 $key');
}

void onCancel() {
print('取消');
}

@override
Widget build(BuildContext context) {
return ExamplePage(
title: tdTitle(),
exampleCodeGroup: 'upload',
desc: '上传组件',
children: [
ExampleModule(
title: '组件类型',
children: [
ExampleItem(desc: '单选上传', builder: _uploadSingle),
ExampleItem(desc: '多选上传', builder: _uploadMultiple),
],
),
ExampleModule(
title: '组件状态',
children: [
ExampleItem(desc: '加载状态', builder: _uploadLoading),
ExampleItem(desc: '重新上传', builder: _uploadRetry),
ExampleItem(desc: '上传失败', builder: _uploadError),
],
),
]);
}

Widget wrapDemoContainer(String title, {required Widget child}) {
return Container(
padding: const EdgeInsets.all(16),
decoration: const BoxDecoration(color: Colors.white),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TDText(
title,
style: const TextStyle(fontSize: 16),
),
const SizedBox(
height: 16,
),
child
],
),
);
}

@Demo(group: 'upload')
Widget _uploadSingle(BuildContext context) {
return wrapDemoContainer('单选上传',
child: TDUpload(
files: files1,
onClick: onClick,
onCancel: onCancel,
onError: print,
onValidate: print,
onChange: ((files, type) => onVaueChanged(files1, files, type)),
));
}

@Demo(group: 'upload')
Widget _uploadMultiple(BuildContext context) {
return wrapDemoContainer('多选上传',
child: TDUpload(
files: files2,
multiple: true,
max: 9,
onClick: onClick,
onCancel: onCancel,
onError: print,
onValidate: print,
onChange: ((files, type) => onVaueChanged(files2, files, type)),
));
}

@Demo(group: 'upload')
Widget _uploadLoading(BuildContext context) {
return wrapDemoContainer('上传图片',
child: TDUpload(
files: files3,
multiple: true,
max: 9,
onClick: onClick,
onCancel: onCancel,
onError: print,
onValidate: print,
onChange: ((files, type) => onVaueChanged(files3, files, type)),
));
}

@Demo(group: 'upload')
Widget _uploadRetry(BuildContext context) {
return wrapDemoContainer('上传图片',
child: TDUpload(
files: files4,
multiple: true,
max: 9,
onClick: onClick,
onCancel: onCancel,
onError: print,
onValidate: print,
onChange: ((files, type) => onVaueChanged(files4, files, type)),
));
}

@Demo(group: 'upload')
Widget _uploadError(BuildContext context) {
return wrapDemoContainer('上传图片',
child: TDUpload(
files: files5,
multiple: true,
max: 9,
onClick: onClick,
onCancel: onCancel,
onError: print,
onValidate: print,
onChange: ((files, type) => onVaueChanged(files5, files, type)),
));
}
}
Loading

0 comments on commit 0c17ab1

Please sign in to comment.