From a8034e8e5667f3b850337d210ac707f4bd03acdb Mon Sep 17 00:00:00 2001 From: Benson Arafat Date: Sun, 17 Nov 2024 23:52:59 +0100 Subject: [PATCH 01/12] fix: case of GoogleMlKitSubjectionSegmentationPlugin --- .../ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.h | 2 +- .../ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.h b/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.h index d4c491c5..c062c6df 100644 --- a/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.h +++ b/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.h @@ -1,4 +1,4 @@ #import @interface GoogleMlKitSubjectSegmentationPlugin : NSObject -@end +@end \ No newline at end of file diff --git a/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.m b/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.m index 8c703c58..268f5809 100644 --- a/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.m +++ b/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.m @@ -13,4 +13,4 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { result(FlutterMethodNotImplemented); } -@end +@end \ No newline at end of file From a4f66fe9d5283be30897ff252100dc0552e41a56 Mon Sep 17 00:00:00 2001 From: Benson Arafat Date: Sun, 17 Nov 2024 23:57:11 +0100 Subject: [PATCH 02/12] fix: filename case for sensitivity --- ...egmentationPlugin.h => GoogleMlKitSubjectionSegmentationPlugin | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.h => GoogleMlKitSubjectionSegmentationPlugin (100%) diff --git a/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.h b/GoogleMlKitSubjectionSegmentationPlugin similarity index 100% rename from packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.h rename to GoogleMlKitSubjectionSegmentationPlugin From 8ec3757ebd81d7a48711ddf3ad6ee17a82f4828d Mon Sep 17 00:00:00 2001 From: Benson Arafat Date: Mon, 18 Nov 2024 00:00:04 +0100 Subject: [PATCH 03/12] fix: filename case for sensitivity --- .../GoogleMlKitSubjectionSegmentationPlugin.h | 4 ++++ .../GoogleMlKitSubjectionSegmentationPlugin.m | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.h create mode 100644 packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.m diff --git a/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.h b/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.h new file mode 100644 index 00000000..c062c6df --- /dev/null +++ b/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.h @@ -0,0 +1,4 @@ +#import + +@interface GoogleMlKitSubjectSegmentationPlugin : NSObject +@end \ No newline at end of file diff --git a/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.m b/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.m new file mode 100644 index 00000000..268f5809 --- /dev/null +++ b/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.m @@ -0,0 +1,16 @@ +#import "GoogleMlKitSubjectSegmentationPlugin.h" + +@implementation GoogleMlKitSubjectSegmentationPlugin ++ (void)registerWithRegistrar:(NSObject*)registrar { + FlutterMethodChannel* channel = [FlutterMethodChannel + methodChannelWithName:@"google_mlkit_subject_segmentation" + binaryMessenger:[registrar messenger]]; + GoogleMlKitSubjectSegmentationPlugin* instance = [[GoogleMlKitSubjectSegmentationPlugin alloc] init]; + [registrar addMethodCallDelegate:instance channel:channel]; +} + +- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { + result(FlutterMethodNotImplemented); +} + +@end \ No newline at end of file From 7779ce17d2e4e53060d8be5e1d662ed837611a88 Mon Sep 17 00:00:00 2001 From: Benson Arafat Date: Sun, 17 Nov 2024 15:01:17 -0800 Subject: [PATCH 04/12] Delete packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.m --- .../GoogleMlkitSubjectionSegmentationPlugin.m | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.m diff --git a/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.m b/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.m deleted file mode 100644 index 268f5809..00000000 --- a/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlkitSubjectionSegmentationPlugin.m +++ /dev/null @@ -1,16 +0,0 @@ -#import "GoogleMlKitSubjectSegmentationPlugin.h" - -@implementation GoogleMlKitSubjectSegmentationPlugin -+ (void)registerWithRegistrar:(NSObject*)registrar { - FlutterMethodChannel* channel = [FlutterMethodChannel - methodChannelWithName:@"google_mlkit_subject_segmentation" - binaryMessenger:[registrar messenger]]; - GoogleMlKitSubjectSegmentationPlugin* instance = [[GoogleMlKitSubjectSegmentationPlugin alloc] init]; - [registrar addMethodCallDelegate:instance channel:channel]; -} - -- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - result(FlutterMethodNotImplemented); -} - -@end \ No newline at end of file From 99b10f8b03322174a059771597bd6e46722d1a75 Mon Sep 17 00:00:00 2001 From: Benson Arafat Date: Tue, 19 Nov 2024 05:27:23 -0800 Subject: [PATCH 05/12] Update GoogleMlKitSubjectionSegmentationPlugin.h --- .../ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.h b/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.h index c062c6df..d4c491c5 100644 --- a/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.h +++ b/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.h @@ -1,4 +1,4 @@ #import @interface GoogleMlKitSubjectSegmentationPlugin : NSObject -@end \ No newline at end of file +@end From 8da8f94f8aaca559578d1aa0bc2be823a5b42d6e Mon Sep 17 00:00:00 2001 From: Benson Arafat Date: Tue, 19 Nov 2024 05:27:35 -0800 Subject: [PATCH 06/12] Update GoogleMlKitSubjectionSegmentationPlugin.m --- .../ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.m b/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.m index 268f5809..8c703c58 100644 --- a/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.m +++ b/packages/google_mlkit_subject_segmentation/ios/Classes/GoogleMlKitSubjectionSegmentationPlugin.m @@ -13,4 +13,4 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { result(FlutterMethodNotImplemented); } -@end \ No newline at end of file +@end From 392a4b6f26425b208027faf5fd5ce289484ab6b8 Mon Sep 17 00:00:00 2001 From: Benson Arafat Date: Tue, 19 Nov 2024 18:27:35 +0100 Subject: [PATCH 07/12] Remove file --- GoogleMlKitSubjectionSegmentationPlugin | 4 ---- packages/example/ios/Podfile.lock | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 GoogleMlKitSubjectionSegmentationPlugin diff --git a/GoogleMlKitSubjectionSegmentationPlugin b/GoogleMlKitSubjectionSegmentationPlugin deleted file mode 100644 index c062c6df..00000000 --- a/GoogleMlKitSubjectionSegmentationPlugin +++ /dev/null @@ -1,4 +0,0 @@ -#import - -@interface GoogleMlKitSubjectSegmentationPlugin : NSObject -@end \ No newline at end of file diff --git a/packages/example/ios/Podfile.lock b/packages/example/ios/Podfile.lock index 4cf4c633..a9b8a452 100644 --- a/packages/example/ios/Podfile.lock +++ b/packages/example/ios/Podfile.lock @@ -402,7 +402,7 @@ SPEC CHECKSUMS: google_mlkit_pose_detection: 3e38d756c918444cc462692f4c745546313dea54 google_mlkit_selfie_segmentation: 9d937dee1df7c7869209a3ffc140495d60a55797 google_mlkit_smart_reply: a168a050579ca554221aa3a64e1eedda4b3635eb - google_mlkit_subject_segmentation: ae6b69afae87a220d410b02d6cdc8dd4bce3139b + google_mlkit_subject_segmentation: 7061b004cd76284f5fad40bdd09089316fcddabc google_mlkit_text_recognition: e540f2aff997f2b0daaa1b4fd5ead3b0b7030adc google_mlkit_translation: d7f4dbc00677b2ef0a35e16be1c2c3172ac157d6 GoogleDataTransport: aae35b7ea0c09004c3797d53c8c41f66f219d6a7 From 420af8724f11eca3cbb261e54b542ac60be3f694 Mon Sep 17 00:00:00 2001 From: Benson Arafat Date: Tue, 19 Nov 2024 18:29:31 +0100 Subject: [PATCH 08/12] revert podfile.lock --- packages/example/ios/Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/example/ios/Podfile.lock b/packages/example/ios/Podfile.lock index a9b8a452..4cf4c633 100644 --- a/packages/example/ios/Podfile.lock +++ b/packages/example/ios/Podfile.lock @@ -402,7 +402,7 @@ SPEC CHECKSUMS: google_mlkit_pose_detection: 3e38d756c918444cc462692f4c745546313dea54 google_mlkit_selfie_segmentation: 9d937dee1df7c7869209a3ffc140495d60a55797 google_mlkit_smart_reply: a168a050579ca554221aa3a64e1eedda4b3635eb - google_mlkit_subject_segmentation: 7061b004cd76284f5fad40bdd09089316fcddabc + google_mlkit_subject_segmentation: ae6b69afae87a220d410b02d6cdc8dd4bce3139b google_mlkit_text_recognition: e540f2aff997f2b0daaa1b4fd5ead3b0b7030adc google_mlkit_translation: d7f4dbc00677b2ef0a35e16be1c2c3172ac157d6 GoogleDataTransport: aae35b7ea0c09004c3797d53c8c41f66f219d6a7 From e725ed385ac674a36f4fe38af440e5f5b23e38bb Mon Sep 17 00:00:00 2001 From: Benson Arafat Date: Mon, 15 Dec 2025 00:00:52 +0100 Subject: [PATCH 09/12] Update the document scanner from beta --- README.md | 2 +- .../document_scanner_view.dart | 10 +++-- .../google_mlkit_document_scanner/README.md | 7 ++- .../android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 7 +++ .../DocumentScanner.java | 44 ++++++++++++++----- .../lib/src/document_scanner.dart | 8 ++-- 7 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 packages/google_mlkit_document_scanner/android/gradle/wrapper/gradle-wrapper.properties diff --git a/README.md b/README.md index 8e097a7f..9c321d16 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Google's ML Kit for Flutter is a set of [Flutter plugins](https://flutter.io/pla | [Pose Detection (Beta)](https://developers.google.com/ml-kit/vision/pose-detection) | [google_mlkit_pose_detection](https://pub.dev/packages/google_mlkit_pose_detection) [![Pub Version](https://img.shields.io/pub/v/google_mlkit_pose_detection)](https://pub.dev/packages/google_mlkit_pose_detection) | [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/flutter-ml/google_ml_kit_flutter/tree/master/packages/google_mlkit_pose_detection) | ✅ | ✅ | | [Selfie Segmentation (Beta)](https://developers.google.com/ml-kit/vision/selfie-segmentation) | [google_mlkit_selfie_segmentation](https://pub.dev/packages/google_mlkit_selfie_segmentation) [![Pub Version](https://img.shields.io/pub/v/google_mlkit_selfie_segmentation)](https://pub.dev/packages/google_mlkit_selfie_segmentation) | [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/flutter-ml/google_ml_kit_flutter/tree/master/packages/google_mlkit_selfie_segmentation) | ✅ | ✅ | | [Subject Segmentation (Beta)](https://developers.google.com/ml-kit/vision/subject-segmentation) | [google_mlkit_subject_segmentation](https://pub.dev/packages/google_mlkit_subject_segmentation) [![Pub Version](https://img.shields.io/pub/v/google_mlkit_subject_segmentation)](https://pub.dev/packages/google_mlkit_subject_segmentation) | [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/flutter-ml/google_ml_kit_flutter/tree/master/packages/google_mlkit_subject_segmentation) | ✅ | ❌ | -| [Document Scanner (Beta)](https://developers.google.com/ml-kit/vision/doc-scanner) | [google_mlkit_document_scanner](https://pub.dev/packages/google_mlkit_document_scanner) [![Pub Version](https://img.shields.io/pub/v/google_mlkit_document_scanner)](https://pub.dev/packages/google_mlkit_document_scanner) | [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/flutter-ml/google_ml_kit_flutter/tree/master/packages/google_mlkit_document_scanner) | ✅ | ❌ | +| [Document Scanner (Beta)](https://developers.google.com/ml-kit/vision/doc-scanner) | [google_mlkit_document_scanner](https://pub.dev/packages/google_mlkit_document_scanner) [![Pub Version](https://img.shields.io/pub/v/google_mlkit_document_scanner)](https://pub.dev/packages/google_mlkit_document_scanner) | [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/flutter-ml/google_ml_kit_flutter/tree/master/packages/google_mlkit_document_scanner) | ✅ | ✅ | ### Natural Language APIs diff --git a/packages/example/lib/vision_detector_views/document_scanner_view.dart b/packages/example/lib/vision_detector_views/document_scanner_view.dart index 3eec7b17..22dfb7d0 100644 --- a/packages/example/lib/vision_detector_views/document_scanner_view.dart +++ b/packages/example/lib/vision_detector_views/document_scanner_view.dart @@ -99,7 +99,7 @@ class _DocumentScannerViewState extends State { ), ), ], - if (_result?.images.isNotEmpty == true) ...[ + if (_result?.images?.isNotEmpty == true) ...[ Padding( padding: const EdgeInsets.only( top: 16, bottom: 8, right: 8, left: 8), @@ -108,7 +108,7 @@ class _DocumentScannerViewState extends State { child: Text('Images [0]:')), ), SizedBox( - height: 400, child: Image.file(File(_result!.images.first))), + height: 400, child: Image.file(File(_result!.images!.first))), ], ], ), @@ -117,13 +117,17 @@ class _DocumentScannerViewState extends State { } void startScan(DocumentFormat format) async { + const Set documentFormats = { + DocumentFormat.jpeg, + DocumentFormat.pdf + }; try { _result = null; setState(() {}); _documentScanner?.close(); _documentScanner = DocumentScanner( options: DocumentScannerOptions( - documentFormat: format, + documentFormats: documentFormats, mode: ScannerMode.full, isGalleryImport: false, pageLimit: 1, diff --git a/packages/google_mlkit_document_scanner/README.md b/packages/google_mlkit_document_scanner/README.md index b2d1140b..bfc5249c 100644 --- a/packages/google_mlkit_document_scanner/README.md +++ b/packages/google_mlkit_document_scanner/README.md @@ -70,8 +70,13 @@ This feature is still in Beta, and it is only available for Android. Stay tune f #### Create an instance of `DocumentScannerOptions` ```dart +// set output document formats +const Set documentFormats = { + DocumentFormat.jpeg, + DocumentFormat.pdf +}; DocumentScannerOptions documentOptions = DocumentScannerOptions( - documentFormat: DocumentFormat.jpeg, // set output document format + documentFormats: documentFormats, mode: ScannerMode.filter, // to control what features are enabled pageLimit: 1, // setting a limit to the number of pages scanned isGalleryImport: true, // importing from the photo gallery diff --git a/packages/google_mlkit_document_scanner/android/build.gradle b/packages/google_mlkit_document_scanner/android/build.gradle index 91147c2d..8264c2d4 100644 --- a/packages/google_mlkit_document_scanner/android/build.gradle +++ b/packages/google_mlkit_document_scanner/android/build.gradle @@ -36,6 +36,6 @@ android { } dependencies { - implementation("com.google.android.gms:play-services-mlkit-document-scanner:16.0.0-beta1") + implementation("com.google.android.gms:play-services-mlkit-document-scanner:16.0.0") } } diff --git a/packages/google_mlkit_document_scanner/android/gradle/wrapper/gradle-wrapper.properties b/packages/google_mlkit_document_scanner/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..128196a7 --- /dev/null +++ b/packages/google_mlkit_document_scanner/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.0-milestone-1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/packages/google_mlkit_document_scanner/android/src/main/java/com/google_mlkit_document_scanner/DocumentScanner.java b/packages/google_mlkit_document_scanner/android/src/main/java/com/google_mlkit_document_scanner/DocumentScanner.java index 7b84f182..4fe6f0a7 100644 --- a/packages/google_mlkit_document_scanner/android/src/main/java/com/google_mlkit_document_scanner/DocumentScanner.java +++ b/packages/google_mlkit_document_scanner/android/src/main/java/com/google_mlkit_document_scanner/DocumentScanner.java @@ -95,17 +95,30 @@ public void onFailure(@NonNull Exception e) { private GmsDocumentScannerOptions parseOptions(Map options) { boolean isGalleryImportAllowed = (boolean) options.get("isGalleryImport"); int pageLimit = (int) options.get("pageLimit"); - int format; - switch ((String) Objects.requireNonNull(options.get("format"))) { - case "pdf": - format = GmsDocumentScannerOptions.RESULT_FORMAT_PDF; - break; - case "jpeg": - format = GmsDocumentScannerOptions.RESULT_FORMAT_JPEG; - break; - default: - throw new IllegalArgumentException("Not a format:" + options.get("format")); + int formats; + List formatStrings = (List) options.get("formats"); + if (formatStrings == null || formatStrings.isEmpty()) { + String singleFormat = (String) options.get("format"); + if (singleFormat == null) { + singleFormat = "jpeg"; + } + formatStrings = new ArrayList<>(); + formatStrings.add(singleFormat); } + List formatConstants = new ArrayList<>(); + for (String format: formatStrings) { + switch (format) { + case "pdf": + formatConstants.add(GmsDocumentScannerOptions.RESULT_FORMAT_PDF); + break; + case "jpeg": + formatConstants.add(GmsDocumentScannerOptions.RESULT_FORMAT_JPEG); + break; + default: + throw new IllegalArgumentException("Not a format:" + options.get("format")); + } + } + int mode; switch ((String) options.get("mode")) { case "base": @@ -120,7 +133,16 @@ private GmsDocumentScannerOptions parseOptions(Map options) { default: throw new IllegalArgumentException("Not a mode:" + options.get("mode")); } - GmsDocumentScannerOptions.Builder builder = new GmsDocumentScannerOptions.Builder().setGalleryImportAllowed(isGalleryImportAllowed).setPageLimit(pageLimit).setResultFormats(format).setScannerMode(mode); + GmsDocumentScannerOptions.Builder builder = new GmsDocumentScannerOptions + .Builder() + .setGalleryImportAllowed(isGalleryImportAllowed) + .setPageLimit(pageLimit) + .setScannerMode(mode); + + // Set formats + if (!formatConstants.isEmpty()) { + builder.setResultFormats(formatConstants.get(0), formatConstants.stream().skip(1).mapToInt(Integer::intValue).toArray()); + } return builder.build(); } diff --git a/packages/google_mlkit_document_scanner/lib/src/document_scanner.dart b/packages/google_mlkit_document_scanner/lib/src/document_scanner.dart index 1a6a501a..911b3765 100644 --- a/packages/google_mlkit_document_scanner/lib/src/document_scanner.dart +++ b/packages/google_mlkit_document_scanner/lib/src/document_scanner.dart @@ -35,7 +35,7 @@ class DocumentScanner { class DocumentScannerOptions { /// Constructor for [DocumentScannerOptions]. DocumentScannerOptions({ - this.documentFormat = DocumentFormat.jpeg, + this.documentFormats = const {DocumentFormat.jpeg}, this.pageLimit = 1, this.mode = ScannerMode.full, this.isGalleryImport = false, @@ -46,7 +46,7 @@ class DocumentScannerOptions { /// Sets scanner result formats. /// Available formats: PDF, JPG and default format is JPG. - final DocumentFormat documentFormat; + final Set documentFormats; /// Sets the scanner mode which determines what features are enabled. default = ScannerModel.full. final ScannerMode mode; @@ -57,7 +57,7 @@ class DocumentScannerOptions { /// Returns a json representation of an instance of [DocumentScannerOptions]. Map toJson() => { 'pageLimit': pageLimit, - 'format': documentFormat.name, + 'formats': documentFormats.map((f) => f.name).toList(), 'mode': mode.name, 'isGalleryImport': isGalleryImport, }; @@ -82,7 +82,7 @@ class DocumentScanningResult { final DocumentScanningResultPdf? pdf; /// Returns the scanned images or null if `DocumentFormat.jpeg` was not specified when creating the scanner options. - final List images; + final List? images; /// Constructor to create an instance of [DocumentScanningResult]. DocumentScanningResult({required this.pdf, required this.images}); From 6dfa34bbea66047bf137277a4cea8f7ac0bef589 Mon Sep 17 00:00:00 2001 From: Benson Arafat Date: Mon, 15 Dec 2025 07:27:53 +0100 Subject: [PATCH 10/12] fix: Remove unuse format --- .../google_mlkit_document_scanner/DocumentScanner.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/google_mlkit_document_scanner/android/src/main/java/com/google_mlkit_document_scanner/DocumentScanner.java b/packages/google_mlkit_document_scanner/android/src/main/java/com/google_mlkit_document_scanner/DocumentScanner.java index 4fe6f0a7..7c1cec17 100644 --- a/packages/google_mlkit_document_scanner/android/src/main/java/com/google_mlkit_document_scanner/DocumentScanner.java +++ b/packages/google_mlkit_document_scanner/android/src/main/java/com/google_mlkit_document_scanner/DocumentScanner.java @@ -95,16 +95,7 @@ public void onFailure(@NonNull Exception e) { private GmsDocumentScannerOptions parseOptions(Map options) { boolean isGalleryImportAllowed = (boolean) options.get("isGalleryImport"); int pageLimit = (int) options.get("pageLimit"); - int formats; List formatStrings = (List) options.get("formats"); - if (formatStrings == null || formatStrings.isEmpty()) { - String singleFormat = (String) options.get("format"); - if (singleFormat == null) { - singleFormat = "jpeg"; - } - formatStrings = new ArrayList<>(); - formatStrings.add(singleFormat); - } List formatConstants = new ArrayList<>(); for (String format: formatStrings) { switch (format) { From 646f635934ecc5e74f0fef2470a37768c36ac31d Mon Sep 17 00:00:00 2001 From: Benson Arafat Date: Mon, 15 Dec 2025 08:39:18 +0100 Subject: [PATCH 11/12] fix: issue with scanning with single format --- .../document_scanner_view.dart | 153 ++++++++---------- .../DocumentScanner.java | 7 +- 2 files changed, 75 insertions(+), 85 deletions(-) diff --git a/packages/example/lib/vision_detector_views/document_scanner_view.dart b/packages/example/lib/vision_detector_views/document_scanner_view.dart index 22dfb7d0..2fc16694 100644 --- a/packages/example/lib/vision_detector_views/document_scanner_view.dart +++ b/packages/example/lib/vision_detector_views/document_scanner_view.dart @@ -1,9 +1,13 @@ +import 'dart:collection'; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_pdfview/flutter_pdfview.dart'; import 'package:google_mlkit_document_scanner/google_mlkit_document_scanner.dart'; +typedef MenuEntry = DropdownMenuEntry; +const List list = ['Select option', 'pdf', 'jpeg', 'pdf-jpeg']; + class DocumentScannerView extends StatefulWidget { @override State createState() => _DocumentScannerViewState(); @@ -12,7 +16,11 @@ class DocumentScannerView extends StatefulWidget { class _DocumentScannerViewState extends State { DocumentScanner? _documentScanner; DocumentScanningResult? _result; - + static final List menuEntries = UnmodifiableListView( + list.map((String name) => MenuEntry( + value: name, + label: + name == 'Select option' ? name : 'Scan ${name.toUpperCase()}'))); @override void dispose() { _documentScanner?.close(); @@ -27,107 +35,84 @@ class _DocumentScannerViewState extends State { centerTitle: true, elevation: 0, ), - body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Icon( - Icons.document_scanner_outlined, - size: 50, - ), - SizedBox(width: 8), - ElevatedButton( - style: ButtonStyle( - backgroundColor: - WidgetStateProperty.all(Colors.black), - shape: WidgetStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - ), - ), - ), - onPressed: () => startScan(DocumentFormat.pdf), - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 4), - child: const Text( - 'Scan PDF', - style: TextStyle(color: Colors.white), - ), + body: SingleChildScrollView( + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + Icons.document_scanner_outlined, + size: 50, ), + SizedBox(width: 8), + DropdownMenu( + initialSelection: list.first, + onSelected: (String? value) { + if (value != null) { + if (value == 'pdf') { + startScan({DocumentFormat.pdf}); + } + if (value == 'jpeg') { + startScan({DocumentFormat.jpeg}); + } + if (value == 'pdf-jpeg') { + startScan( + {DocumentFormat.pdf, DocumentFormat.jpeg}); + } + } + }, + dropdownMenuEntries: menuEntries), + ], + ), + if (_result?.pdf != null) ...[ + Padding( + padding: const EdgeInsets.only( + top: 16, bottom: 8, right: 8, left: 8), + child: Align( + alignment: Alignment.centerLeft, + child: Text('PDF Document:')), ), - SizedBox(width: 8), - ElevatedButton( - style: ButtonStyle( - backgroundColor: - WidgetStateProperty.all(Colors.black), - shape: WidgetStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - ), - ), - ), - onPressed: () => startScan(DocumentFormat.jpeg), - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 4), - child: const Text( - 'Scan JPEG', - style: TextStyle(color: Colors.white), - ), + SizedBox( + height: 300, + child: PDFView( + filePath: _result!.pdf!.uri, + enableSwipe: true, + swipeHorizontal: true, + autoSpacing: false, + pageFling: false, ), ), ], - ), - if (_result?.pdf != null) ...[ - Padding( - padding: const EdgeInsets.only( - top: 16, bottom: 8, right: 8, left: 8), - child: Align( - alignment: Alignment.centerLeft, - child: Text('PDF Document:')), - ), - SizedBox( - height: 300, - child: PDFView( - filePath: _result!.pdf!.uri, - enableSwipe: true, - swipeHorizontal: true, - autoSpacing: false, - pageFling: false, + if (_result?.images?.isNotEmpty == true) ...[ + Padding( + padding: const EdgeInsets.only( + top: 16, bottom: 8, right: 8, left: 8), + child: Align( + alignment: Alignment.centerLeft, + child: Text('Images [0]:')), ), - ), - ], - if (_result?.images?.isNotEmpty == true) ...[ - Padding( - padding: const EdgeInsets.only( - top: 16, bottom: 8, right: 8, left: 8), - child: Align( - alignment: Alignment.centerLeft, - child: Text('Images [0]:')), - ), - SizedBox( - height: 400, child: Image.file(File(_result!.images!.first))), + SizedBox( + height: 400, + child: Image.file(File(_result!.images!.first))), + ], ], - ], + ), ), ), ); } - void startScan(DocumentFormat format) async { - const Set documentFormats = { - DocumentFormat.jpeg, - DocumentFormat.pdf - }; + void startScan(Set formats) async { try { _result = null; setState(() {}); _documentScanner?.close(); _documentScanner = DocumentScanner( options: DocumentScannerOptions( - documentFormats: documentFormats, + documentFormats: formats, mode: ScannerMode.full, isGalleryImport: false, pageLimit: 1, diff --git a/packages/google_mlkit_document_scanner/android/src/main/java/com/google_mlkit_document_scanner/DocumentScanner.java b/packages/google_mlkit_document_scanner/android/src/main/java/com/google_mlkit_document_scanner/DocumentScanner.java index 7c1cec17..2720b220 100644 --- a/packages/google_mlkit_document_scanner/android/src/main/java/com/google_mlkit_document_scanner/DocumentScanner.java +++ b/packages/google_mlkit_document_scanner/android/src/main/java/com/google_mlkit_document_scanner/DocumentScanner.java @@ -132,7 +132,12 @@ private GmsDocumentScannerOptions parseOptions(Map options) { // Set formats if (!formatConstants.isEmpty()) { - builder.setResultFormats(formatConstants.get(0), formatConstants.stream().skip(1).mapToInt(Integer::intValue).toArray()); + if(formatConstants.size() > 1) { + builder.setResultFormats(formatConstants.get(0), formatConstants.get(1)); + } else { + builder.setResultFormats(formatConstants.get(0)); + } + } return builder.build(); } From d3d6df5e4d370e4df20678758aea46977976cd6d Mon Sep 17 00:00:00 2001 From: Benson Arafat Date: Mon, 15 Dec 2025 22:10:50 +0100 Subject: [PATCH 12/12] Update readme --- README.md | 2 +- packages/google_mlkit_document_scanner/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c321d16..86251ae1 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Google's ML Kit for Flutter is a set of [Flutter plugins](https://flutter.io/pla | [Pose Detection (Beta)](https://developers.google.com/ml-kit/vision/pose-detection) | [google_mlkit_pose_detection](https://pub.dev/packages/google_mlkit_pose_detection) [![Pub Version](https://img.shields.io/pub/v/google_mlkit_pose_detection)](https://pub.dev/packages/google_mlkit_pose_detection) | [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/flutter-ml/google_ml_kit_flutter/tree/master/packages/google_mlkit_pose_detection) | ✅ | ✅ | | [Selfie Segmentation (Beta)](https://developers.google.com/ml-kit/vision/selfie-segmentation) | [google_mlkit_selfie_segmentation](https://pub.dev/packages/google_mlkit_selfie_segmentation) [![Pub Version](https://img.shields.io/pub/v/google_mlkit_selfie_segmentation)](https://pub.dev/packages/google_mlkit_selfie_segmentation) | [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/flutter-ml/google_ml_kit_flutter/tree/master/packages/google_mlkit_selfie_segmentation) | ✅ | ✅ | | [Subject Segmentation (Beta)](https://developers.google.com/ml-kit/vision/subject-segmentation) | [google_mlkit_subject_segmentation](https://pub.dev/packages/google_mlkit_subject_segmentation) [![Pub Version](https://img.shields.io/pub/v/google_mlkit_subject_segmentation)](https://pub.dev/packages/google_mlkit_subject_segmentation) | [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/flutter-ml/google_ml_kit_flutter/tree/master/packages/google_mlkit_subject_segmentation) | ✅ | ❌ | -| [Document Scanner (Beta)](https://developers.google.com/ml-kit/vision/doc-scanner) | [google_mlkit_document_scanner](https://pub.dev/packages/google_mlkit_document_scanner) [![Pub Version](https://img.shields.io/pub/v/google_mlkit_document_scanner)](https://pub.dev/packages/google_mlkit_document_scanner) | [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/flutter-ml/google_ml_kit_flutter/tree/master/packages/google_mlkit_document_scanner) | ✅ | ✅ | +| [Document Scanner](https://developers.google.com/ml-kit/vision/doc-scanner) | [google_mlkit_document_scanner](https://pub.dev/packages/google_mlkit_document_scanner) [![Pub Version](https://img.shields.io/pub/v/google_mlkit_document_scanner)](https://pub.dev/packages/google_mlkit_document_scanner) | [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/flutter-ml/google_ml_kit_flutter/tree/master/packages/google_mlkit_document_scanner) | ✅ | ❌ | ### Natural Language APIs diff --git a/packages/google_mlkit_document_scanner/README.md b/packages/google_mlkit_document_scanner/README.md index bfc5249c..51140978 100644 --- a/packages/google_mlkit_document_scanner/README.md +++ b/packages/google_mlkit_document_scanner/README.md @@ -55,7 +55,7 @@ The document scanner API provides a high-quality fully fledged UI flow that is c ### iOS -This feature is still in Beta, and it is only available for Android. Stay tune for updates in [Google's website](https://developers.google.com/ml-kit/vision/doc-scanner) and request the feature [here](https://github.com/googlesamples/mlkit/issues). +This feature is only available for Android. Stay tune for updates in [Google's website](https://developers.google.com/ml-kit/vision/doc-scanner) and request the feature [here](https://github.com/googlesamples/mlkit/issues). ### Android