From 697d44635c21b96a2d10a1a22f2fc1924fd9d05b Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Tue, 6 Feb 2024 11:01:16 +0300 Subject: [PATCH] Storage permissions handled --- .../itg_fragments/attachments_fragment.dart | 5 ++++- .../attachments_fragment.dart | 5 ++++- lib/widgets/image_picker.dart | 21 ++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/ui/work_list/itg_fragments/attachments_fragment.dart b/lib/ui/work_list/itg_fragments/attachments_fragment.dart index a4a8372..ec109e7 100644 --- a/lib/ui/work_list/itg_fragments/attachments_fragment.dart +++ b/lib/ui/work_list/itg_fragments/attachments_fragment.dart @@ -33,7 +33,7 @@ class ITGAttachmentsFragment extends StatelessWidget { ).objectContainerView().onPress(() async { try { Permission.storage.isGranted.then( - (isGranted) { + (isGranted) async { if (!isGranted) { Permission.manageExternalStorage.request().then( (granted) async { @@ -53,6 +53,9 @@ class ITGAttachmentsFragment extends StatelessWidget { } }, ); + } else { + String path = await _createFileFromString(itgFormAttachmentsList[index].fileBase64 ?? "", itgFormAttachmentsList[index].fileType ?? ""); + OpenFile.open(path); } }, ); diff --git a/lib/ui/work_list/worklist_fragments/attachments_fragment.dart b/lib/ui/work_list/worklist_fragments/attachments_fragment.dart index 01a075b..93309f1 100644 --- a/lib/ui/work_list/worklist_fragments/attachments_fragment.dart +++ b/lib/ui/work_list/worklist_fragments/attachments_fragment.dart @@ -33,7 +33,7 @@ class AttachmentsFragment extends StatelessWidget { ).objectContainerView().onPress(() async { try { Permission.storage.isGranted.then( - (isGranted) { + (isGranted) async { if (!isGranted) { Permission.manageExternalStorage.request().then( (granted) async { @@ -53,6 +53,9 @@ class AttachmentsFragment extends StatelessWidget { } }, ); + } else { + String path = await _createFileFromString(getAttachmentList[index].fILEDATA ?? "", getAttachmentList[index].fILECONTENTTYPE ?? ""); + OpenFile.open(path); } }, ); diff --git a/lib/widgets/image_picker.dart b/lib/widgets/image_picker.dart index 19b1e00..b98d80d 100644 --- a/lib/widgets/image_picker.dart +++ b/lib/widgets/image_picker.dart @@ -45,7 +45,7 @@ class ImageOptions { } }, onFilesTap: () async { - Permission.storage.isGranted.then((isGranted) { + Permission.storage.isGranted.then((isGranted) async { if (!isGranted) { Permission.manageExternalStorage.request().then((granted) async { if (granted == PermissionStatus.granted) { @@ -79,6 +79,25 @@ class ImageOptions { ); } }); + } else { + FilePickerResult? result = await FilePicker.platform.pickFiles( + type: FileType.custom, + allowedExtensions: [ + 'jpg', + 'jpeg ', + 'pdf', + 'txt', + 'docx', + 'doc', + 'pptx', + 'xlsx', + 'png', + 'rar', + 'zip', + ], + ); + List files = result!.paths.map((path) => File(path!)).toList(); + image(result.files.first.path.toString(), files.first); } }); },