miguelpruivo / flutter_file_picker

File picker plugin for Flutter, compatible with mobile (iOS & Android), Web, Desktop (Mac, Linux, Windows) platforms with Flutter Go support.
MIT License
1.32k stars 653 forks source link

App Crash on Android 8 #1584

Open girish54321 opened 3 weeks ago

girish54321 commented 3 weeks ago

Thanks for This Amazing package.

Describe the bug File Picker with image works fine but in android 8 afther you pick file it crash

Platform

Platform OS version Android 8

How are you picking?

  Future<void> pickMyCard() async {
    FilePickerResult? result = await FilePicker.platform.pickFiles(
      type: FileType.image,
    );
    if (result != null) {
      setState(() {
        drivingLicense = result.files.single;
      });
      File file = File(result.files.single.path ?? "");
      CroppedFile? croppedImage = await cropImage(file);
      if (croppedImage != null) {
        setState(() {
          drivingLicensePath = croppedImage;
        });
      }
    }
  }

//* My Crop image function

  Future<CroppedFile?> cropImage(File file) async {
    CroppedFile? croppedFile = await ImageCropper().cropImage(
      sourcePath: file.path,
      aspectRatio: const CropAspectRatio(ratioX: 16.0, ratioY: 9.0),
      // aspectRatioPresets: [CropAspectRatioPreset.ratio16x9],
      uiSettings: [
        AndroidUiSettings(
            toolbarTitle: 'Pick Image',
            toolbarColor: Colors.indigo,
            toolbarWidgetColor: Colors.white,
            initAspectRatio: CropAspectRatioPreset.original,
            lockAspectRatio: false),
        IOSUiSettings(
          title: 'Pick Image',
        ),
        WebUiSettings(
          context: context,
        ),
      ],
    );
    return croppedFile;
  }

Details to reproduce the issue

  1. Run the app
  2. Request for pickFiles with type type: FileType.image,

Error Log

Fatal Exception: java.lang.RuntimeException
java.io.IOException: Permission denied 

          Fatal Exception: java.lang.RuntimeException: java.io.IOException: Permission denied
       at com.mr.flutter.plugin.filepicker.FileUtils.compressImage(FileUtils.java:57)
       at com.mr.flutter.plugin.filepicker.FilePickerDelegate$2.run(FilePickerDelegate.java:200)
       at java.lang.Thread.run(Thread.java:764)
 Caused by java.io.IOException
Permission denied 

          Caused by java.io.IOException: Permission denied
       at java.io.UnixFileSystem.createFileExclusively0(UnixFileSystem.java)
       at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:281)
       at java.io.File.createTempFile(File.java:2001)
       at com.mr.flutter.plugin.filepicker.FileUtils.createImageFile(FileUtils.java:46)
       at com.mr.flutter.plugin.filepicker.FileUtils.compressImage(FileUtils.java:8)
       at com.mr.flutter.plugin.filepicker.FilePickerDelegate$2.run(FilePickerDelegate.java:200)
       at java.lang.Thread.run(Thread.java:764)

Screenshots and/or video Added

Flutter Version details

Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel stable, 3.24.0, on macOS 14.5 23F79 darwin-x64, locale
    en-IN)
    ! Warning: `dart` on your path resolves to
      /usr/local/Cellar/dart/3.2.6/libexec/bin/dart, which is not inside your
      current Flutter SDK checkout at
      /Users/girishparate/Documents/tool/flutter. Consider adding
      /Users/girishparate/Documents/tool/flutter/bin to the front of your path.
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor
      --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.92.2)
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 2 categories.

Additional context Works fine with android 13, App Crash happens

https://github.com/user-attachments/assets/b4759c85-0193-43e5-9619-610b30b7e9e6

in Real phone too

ali2236 commented 3 weeks ago

Can this be related?

kareemmuhamedd commented 3 weeks ago

I encountered the same issue with android 10. Does anyone have a solution? 🐛

github-actions[bot] commented 1 week ago

This issue is stale because it has been open for 7 days with no activity.

mrRedSun commented 1 week ago

Setting compressionQuality to 0 prevents the code from going to that method and prevents the crash, but is actually problematic for us and doesn't really solve the underlying issue. It happens on Android 10 as well as 11 for me. 11 is a real LG device, so it's not a simulator only issue.

      final result = await _filePicker.pickFiles(
        type: FileType.image,
        compressionQuality: 0,
        allowCompression: false,
        allowMultiple: false,
      );
github-actions[bot] commented 3 days ago

This issue is stale because it has been open for 7 days with no activity.