eliasteeny / flutter_document_scanner

Document scanner plugin ported from react native to flutter
MIT License
38 stars 26 forks source link

Crash after scanning the document #8

Closed annkitpanwar closed 3 years ago

annkitpanwar commented 3 years ago

I am using document_scanner: ^0.1.1. When app scan the document, and when i am using scannedImage.getScannedDocumentAsFile() for getting File, Its getting crash with below message.

java.lang.IllegalArgumentException: Requested path /data/data/com.abc/cache/documents/cc53d53c-1ac2-405f-b1b4-b01cc53c028e.jpg doesn't appear under [/storage/emulated/0]

my flutter doctor -v is

[✓] Flutter (Channel stable, 2.0.4, on macOS 11.2.3 20D91 darwin-x64, locale en-IN)
    • Flutter version 2.0.4 at /Users/ankitpanwar/Library/Flutter/flutter
    • Framework revision b1395592de (3 weeks ago), 2021-04-01 14:25:01 -0700
    • Engine revision 2dce47073a
    • Dart version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    • Android SDK at /Users/ankitpanwar/Library/Android/sdk
    • Platform android-30, build-tools 30.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] Connected device (2 available)
    • Redmi Note 8 Pro (mobile) • u8kftw59gio7qkjr • android-arm64  • Android 10 (API 29)
    • Chrome (web)              • chrome           • web-javascript • Google Chrome 90.0.4430.72

• No issues found!
eliasteeny commented 3 years ago

I just tried it in a new project and it worked as expected. Please share a code snippet of how you're using scannedImage.getScannedDocumentAsFile() and the value of scannedImage.croppedImage. You can output it using : print(scannedImage.croppedImage);

annkitpanwar commented 3 years ago

Hi, thanks for the reply.

here is my code

  Future<void> _onClickScanDocument(context, ScannedImage scannedImage) async {
    print("ScanDocument: ${scannedImage.toJson()}");
    if (scannedImage.croppedImage != null) {
      if (widget.from == VALUE_INTRO) {
        _bloc.fileSink.add(scannedImage.getScannedDocumentAsFile());
      } else {
        Navigator.of(context).pop(scannedImage.getScannedDocumentAsFile());
      }
    }
  }

and here is the scanned image data

I/flutter (22635): ScanDocument: {"croppedImage":"file:///data/user/0/com.possibility.algo/cache/documents/1dd202ad-0653-4dda-9b2a-b30bd646842c.jpg","width":499,"initialImage":"file:///data/user/0/com.possibility.algo/cache/documents/b1e0f7da-54b9-43e5-a2a9-05f91dd9f1e7.jpg","height":888}

The full error is below

E/AndroidRuntime(22635): FATAL EXCEPTION: Worker Thread
E/AndroidRuntime(22635): Process: com.possibility.algo, PID: 22635
E/AndroidRuntime(22635): java.lang.IllegalArgumentException: Requested path /data/data/com.possibility.algo/cache/documents/1dd202ad-0653-4dda-9b2a-b30bd646842c.jpg doesn't appear under [/storage/emulated/0]
E/AndroidRuntime(22635):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:170)
E/AndroidRuntime(22635):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
E/AndroidRuntime(22635):    at android.content.ContentProviderProxy.insert(ContentProviderNative.java:481)
E/AndroidRuntime(22635):    at android.content.ContentResolver.insert(ContentResolver.java:1841)
E/AndroidRuntime(22635):    at com.example.document_scanner.helpers.Utils.addImageToGallery(Utils.java:215)
E/AndroidRuntime(22635):    at com.example.document_scanner.views.OpenNoteCameraView.saveDocument(OpenNoteCameraView.java:741)
E/AndroidRuntime(22635):    at com.example.document_scanner.ImageProcessor.processPicture(ImageProcessor.java:190)
E/AndroidRuntime(22635):    at com.example.document_scanner.ImageProcessor.handleMessage(ImageProcessor.java:116)
E/AndroidRuntime(22635):    at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(22635):    at android.os.Looper.loop(Looper.java:224)
E/AndroidRuntime(22635):    at android.os.HandlerThread.run(HandlerThread.java:67)
I/Process (22635): Sending signal. PID: 22635 SIG: 9
eliasteeny commented 3 years ago

Please check version 0.1.2 if the problem is resolved. I can't confirm it, because the problem isn't occurring on my device.

annkitpanwar commented 3 years ago

Thanks @eliasteeny for quick support, version 0.1.2 fixed this issue.