Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #104

Merged
merged 18 commits into from
Jan 17, 2025
Merged

Dev #104

Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(edit): add multi image picker support
  • Loading branch information
ZhuJHua committed Jan 17, 2025
commit bd2d91b07a8423d692a8340f39df83cf4bdae110
34 changes: 15 additions & 19 deletions lib/pages/edit/edit_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ class EditLogic extends GetxController {
update(['Image']);
}

// 多张图片

Future<void> pickMultiPhoto(BuildContext context) async {
final List<XFile> photoList = await MediaUtil.pickMultiPhoto(10);
if (photoList.isNotEmpty && context.mounted) {
Navigator.pop(context);
for (var photo in photoList) {
await addNewImage(photo);
}
return;
} else {
NoticeUtil.showToast('取消图片选择');
}
}

//单张照片
Future<void> pickPhoto(ImageSource imageSource, BuildContext context) async {
//获取一张图片
Expand Down Expand Up @@ -245,25 +260,6 @@ class EditLogic extends GetxController {
addNewImage(XFile.fromData(imageData, path: path)..saveTo(path));
}

//相册选择多张照片
Future<void> pickMultiPhoto(BuildContext context) async {
//获取一堆照片
List<XFile> photoList = await MediaUtil.pickMultiPhoto(null);
if (photoList.isNotEmpty && context.mounted) {
//关闭dialog
Navigator.pop(context);
// if (photoList.length > 10 - state.imageFileList.length) {
// photoList = photoList.sublist(0, 10 - state.imageFileList.length);
// }
for (var photo in photoList) {
addNewImage(photo);
}
} else {
//弹出一个提示
NoticeUtil.showToast('取消图片选择');
}
}

Future<void> addNewVideo(XFile xFile) async {
//视频list中新增一个
state.videoFileList.add(xFile);
Expand Down
9 changes: 7 additions & 2 deletions lib/pages/edit/edit_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,9 @@ class EditPage extends StatelessWidget {
],
),
onPressed: () async {
await logic.pickPhoto(ImageSource.gallery, context);
await logic.pickMultiPhoto(
context,
);
},
),
if (Platform.isAndroid || Platform.isIOS)
Expand All @@ -435,7 +437,10 @@ class EditPage extends StatelessWidget {
],
),
onPressed: () async {
await logic.pickPhoto(ImageSource.camera, context);
await logic.pickPhoto(
ImageSource.camera,
context,
);
},
),
SimpleDialogOption(
Expand Down