diff --git a/lib/helpers/firebase_helper.dart b/lib/helpers/firebase_helper.dart index 2febc03..f6d95c5 100644 --- a/lib/helpers/firebase_helper.dart +++ b/lib/helpers/firebase_helper.dart @@ -23,6 +23,17 @@ Future getClaims({bool refreshIdToken = false}) async { return idToken.claims; } +// returns list of url +Future> uploadFiles(String path, List files, + {String fileName}) async { + List> fu = []; + for (File f in files) { + Future u = uploadStorage(path, f); + fu.add(u); + } + return Future.wait(fu); +} + Future uploadStorage(String path, File file, {String fileName}) async { if (fileName == null) { fileName = Uuid().v4(); diff --git a/lib/pages/package/model/package_model.dart b/lib/pages/package/model/package_model.dart index 2dd4fd1..f3f5470 100644 --- a/lib/pages/package/model/package_model.dart +++ b/lib/pages/package/model/package_model.dart @@ -255,11 +255,11 @@ class PackageModel extends BaseModel { if (files.length > uploadPhotoLimit) throw Exception("Exceed number of file upload"); package.photoUrls = package.photoUrls == null ? [] : package.photoUrls; - for (File f in files) { - String path = Path.join(pkg_files_path); - String url = await uploadStorage(path, f); + String path = Path.join(pkg_files_path); + List urls = await uploadFiles(path, files); + urls.forEach((url) { package.photoUrls.add(url); - } + }); } return Services.instance.packageService.createReceiving(package); } @@ -284,11 +284,11 @@ class PackageModel extends BaseModel { if (count > uploadPhotoLimit) throw Exception("Exceed number of file upload"); package.photoUrls = package.photoUrls == null ? [] : package.photoUrls; - for (File f in files) { - String path = Path.join(pkg_files_path); - String url = await uploadStorage(path, f); + String path = Path.join(pkg_files_path); + List urls = await uploadFiles(path, files); + urls.forEach((url) { package.photoUrls.add(url); - } + }); } await Services.instance.packageService.updateReceiving(package); } @@ -314,11 +314,11 @@ class PackageModel extends BaseModel { if (count > uploadPhotoLimit) throw Exception("Exceed number of file upload"); package.photoUrls = package.photoUrls == null ? [] : package.photoUrls; - for (File f in files) { - String path = Path.join(pkg_files_path); - String url = await uploadStorage(path, f); + String path = Path.join(pkg_files_path); + List urls = await uploadFiles(path, files); + urls.forEach((url) { package.photoUrls.add(url); - } + }); package.photoUrls.removeWhere((e) => deletedUrls.contains(e)); } await Services.instance.packageService.updateProcessing(package);