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

Allowing Import Image from Gallery on Android #51

Merged
merged 6 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ The easiest way to get a list of images is:
final imagesPath = await CunningDocumentScanner.getPictures()
```

Additionally you can limit the number of pages as follows:
You can limit the number of pages as follows:

```
final imagesPath = await CunningDocumentScanner.getPictures(noOfPages: 1)
```

In addition, and only on Android for now, you can allow importing images from the gallery:

```
final imagesPath = await CunningDocumentScanner.getPictures(isGalleryImportAllowed: true)
```

This would limit the number of pages to one.

## Contributing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ class CunningDocumentScannerPlugin : FlutterPlugin, MethodCallHandler, ActivityA
override fun onMethodCall(call: MethodCall, result: Result) {
if (call.method == "getPictures") {
val noOfPages = call.argument<Int>("noOfPages") ?: 50;
val isGalleryImportAllowed = call.argument<Boolean>("isGalleryImportAllowed") ?: false;
this.pendingResult = result
startScan(noOfPages)
startScan(noOfPages, isGalleryImportAllowed)
} else {
result.notImplemented()
}
Expand Down Expand Up @@ -105,9 +106,9 @@ class CunningDocumentScannerPlugin : FlutterPlugin, MethodCallHandler, ActivityA
/**
* add document scanner result handler and launch the document scanner
*/
private fun startScan(noOfPages: Int) {
private fun startScan(noOfPages: Int, isGalleryImportAllowed: Boolean) {
val options = GmsDocumentScannerOptions.Builder()
.setGalleryImportAllowed(false)
.setGalleryImportAllowed(isGalleryImportAllowed)
.setPageLimit(noOfPages)
.setResultFormats(RESULT_FORMAT_JPEG)
.setScannerMode(SCANNER_MODE_FULL)
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.1.5"
version: "1.2.0"
cupertino_icons:
dependency: "direct main"
description:
Expand Down
8 changes: 5 additions & 3 deletions lib/cunning_document_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CunningDocumentScanner {

/// Call this to start get Picture workflow.
static Future<List<String>?> getPictures(
{int noOfPages = 100}) async {
{int noOfPages = 100, bool isGalleryImportAllowed = false}) async {
Map<Permission, PermissionStatus> statuses = await [
Permission.camera,
].request();
Expand All @@ -18,8 +18,10 @@ class CunningDocumentScanner {
throw Exception("Permission not granted");
}

final List<dynamic>? pictures = await _channel.invokeMethod('getPictures',
{'noOfPages': noOfPages});
final List<dynamic>? pictures = await _channel.invokeMethod('getPictures', {
'noOfPages': noOfPages,
'isGalleryImportAllowed': isGalleryImportAllowed
});
return pictures?.map((e) => e as String).toList();
}
}
Loading