Skip to content

Commit

Permalink
feat(file-upload): implemented file service functions (#91)
Browse files Browse the repository at this point in the history
* 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
Khushhbboo authored and singhtaranjeet committed Jun 20, 2024
1 parent 8abc7b8 commit c94afe0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lib/src/modules/common/file_upload/file_uploader.dart
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);
}
}
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.0"
file_picker:
dependency: "direct main"
description:
name: file_picker
sha256: "2ca051989f69d1b2ca012b2cf3ccf78c70d40144f0861ff2c063493f7c8c3d45"
url: "https://pub.dev"
source: hosted
version: "8.0.5"
file_selector_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -1092,6 +1100,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.0"
open_file:
dependency: "direct main"
description:
name: open_file
sha256: a5a32d44acb7c899987d0999e1e3cbb0a0f1adebbf41ac813ec6d2d8faa0af20
url: "https://pub.dev"
source: hosted
version: "3.3.2"
package_config:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dependencies:
qr_code_scanner: ^1.0.1
speech_to_text: ^6.6.0
flutter_tts: ^4.0.2
file_picker: ^8.0.0+1
open_file: ^3.3.2

# Core
fa_flutter_core:
Expand Down

0 comments on commit c94afe0

Please sign in to comment.