-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(file-upload): implemented file service functions (#91)
* fix(file-upload): implement static functions * fix(file-upload): formatting code * fix(file-upload): adding docs * fix(file-upload): passing required correct parameter * fix(file-upload): document handled extensions * fix(file-upload): minor changes * fix(file-upload): removed obvious comment
- Loading branch information
1 parent
8abc7b8
commit c94afe0
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:fa_flutter_core/fa_flutter_core.dart'; | ||
import 'package:file_picker/file_picker.dart'; | ||
import 'package:open_file/src/platform/open_file.dart'; | ||
|
||
class FileService { | ||
FileService._(); | ||
|
||
/// Return the Clicked Image | ||
static Future<PlatformFile?> pickImage( | ||
ImageSource source, String? name) async { | ||
final pickedFile = await ImagePicker().pickImage(source: source); | ||
|
||
if (pickedFile != null) { | ||
return PlatformFile( | ||
name: name ?? pickedFile.name, | ||
size: await pickedFile.length(), | ||
path: pickedFile.path, | ||
); | ||
} | ||
return null; | ||
} | ||
|
||
/// Return the Picked File from the System | ||
/// handled extensions are [pdf, jpeg, jpg, png] | ||
/// We can add more via [extension] parameter | ||
static Future<PlatformFile?> pickDocument(List<String>? extensions) async { | ||
FilePickerResult? result = await FilePicker.platform.pickFiles( | ||
type: FileType.custom, | ||
allowedExtensions: extensions ?? | ||
[ | ||
'pdf', | ||
'jpg', | ||
'jpeg', | ||
'png', | ||
], | ||
); | ||
if (result != null) return result.files.first; | ||
return null; | ||
} | ||
|
||
/// Open the DOC | ||
static void openFile(String path) { | ||
OpenFile.open(path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters