ko2ic / image_downloader

Flutter plugin that downloads images and movies on the Internet and saves to Photo Library on iOS or specified directory on Android.
https://pub.dartlang.org/packages/image_downloader#-readme-tab-
MIT License
92 stars 115 forks source link

Preview download image abnormal on Android device. #76

Open jasoncheng opened 4 years ago

jasoncheng commented 4 years ago

When i try .open for preview downloaded image, it's keep loading; no idea if this my phone issue or Google Album bugs or something else, anyone ?

Thanks

Video https://drive.google.com/file/d/1c8FePBqXWgBITQkfzz1wTOmz07Vc43I2/view?usp=sharing

Sample Code

downloadResource(BuildContext context, String url) async {
    String cachedPath = _downloadedPath[url];
    if(cachedPath != null){
      debugPrint("${this.runtimeType}.downloadResource cached $url, $cachedPath");
      return _previewDownloadImage(cachedPath);
    }

    CommonWidget.toastOk('downloading');
    try {
      var imageId = await ImageDownloader.downloadImage(url);
      if (imageId == null) {
        CommonWidget.toastFail('downloadRequirePermission');
        return;
      }
      CommonWidget.toastOk('downloaded');
      bool preview =
          await CommonWidget.alertDialog(context, AppLocalizations.$t('previewImage'), AppLocalizations.$t('previewImageDesc'));
      if (!preview) return;

      var path = await ImageDownloader.findPath(imageId);
      _downloadedPath[url] = path;
      debugPrint("${this.runtimeType}.downloadResource $url, ${_downloadedPath[url]}");
      _previewDownloadImage(path);
    } catch (e) {
      CommonWidget.toastFailWithText(sprintf(AppLocalizations.$t('downloadFail'), ["$e"]));
    }
  }

  _previewDownloadImage(String path) => ImageDownloader.open(path).catchError((error) {
        if (error is PlatformException) {
          if (error.code == "preview_error") {
            CommonWidget.toastFailWithText(
                sprintf(AppLocalizations.$t('previewError'), [error.message]));
          }
        }
      });

Futter doctor [✓] Flutter (Channel master, 1.19.0-1.0.pre.26, on Mac OS X 10.15.4 19E287, locale zh-Hant-TW) • Flutter version 1.19.0-1.0.pre.26 at /Users/jason/flutter • Framework revision 793e6a48a1 (2 days ago), 2020-05-10 12:14:01 +0800 • Engine revision 9b905d3f03 • Dart version 2.9.0 (build 2.9.0-7.0.dev 617bc54b71)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) • Android SDK at /Users/jason/Library/Android/sdk • Platform android-29, build-tools 28.0.3 • ANDROID_HOME = /Users/jason/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 11.4.1, Build version 11E503a • CocoaPods version 1.9.1

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

[✓] Android Studio (version 3.6) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 45.1.1 • Dart plugin version 192.7761 • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] VS Code (version 1.45.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.10.1

[✓] Connected device (4 available)
• Mi A2 • fb24c6 • android-arm64 • Android 10 (API 29) • macOS • macOS • darwin-x64 • Mac OS X 10.15.4 19E287 • Web Server • web-server • web-javascript • Flutter Tools • Chrome • chrome • web-javascript • Google Chrome 81.0.4044.138

• No issues found!