флаттер image_downloader 0.19.2 cra sh после завершения загрузки - PullRequest
0 голосов
/ 18 апреля 2020

Я использую image_downloader 0.19.2 ссылка для загрузки изображений JPEG в папку «Изображения» / подпапку во внешней памяти.

Загрузка начинается, иногда приложение неожиданно падает, а иногда просто работает .

Я не смог прочитать ни одного исключения или ошибки!

Я тестирую приложение на 3 устройствах и эмуляторе с android версиями от 6 до 10.

Launching lib\main.dart on SM N960F in profile mode...
Running Gradle task 'assembleProfile'...
√ Built build\app\outputs\apk\profile\app-profile.apk (11.7MB).
Installing build\app\outputs\apk\app.apk...
Debug service listening on ws://127.0.0.1:53603/Z0HTCq4Xk7c=/ws
D/ViewRootImpl@9967f53[MainActivity]( 5951): ViewPostIme pointer 0
D/ViewRootImpl@9967f53[MainActivity]( 5951): ViewPostIme pointer 1
D/ViewRootImpl@9967f53[MainActivity]( 5951): ViewPostIme pointer 0
D/ViewRootImpl@9967f53[MainActivity]( 5951): ViewPostIme pointer 1
D/image_downloader( 5951): RequestResult(id=5626, remoteUri=https://pixabay.com/get/57e6d344495ab108f5d084609629317e1638dde5514c704c7d2879d59749c25e_1280.jpg, localUri=null, mediaType=null, totalSize=-1, title=, description=)
D/image_downloader( 5951): 0
D/image_downloader( 5951): RequestResult(id=5626, remoteUri=https://pixabay.com/get/57e6d344495ab108f5d084609629317e1638dde5514c704c7d2879d59749c25e_1280.jpg, localUri=null, mediaType=null, totalSize=-1, title=, description=)
D/image_downloader( 5951): 0
D/image_downloader( 5951): RequestResult(id=5626, remoteUri=https://pixabay.com/get/57e6d344495ab108f5d084609629317e1638dde5514c704c7d2879d59749c25e_1280.jpg, localUri=file:///storage/emulated/0/Pictures/AwesomeWallpapers/awesomeWallpaper-7.jpg, mediaType=image/jpeg, totalSize=172875, title=awesomeWallpaper-7.jpg, description=)
D/image_downloader( 5951): 0
D/image_downloader( 5951): RequestResult(id=5626, remoteUri=https://pixabay.com/get/57e6d344495ab108f5d084609629317e1638dde5514c704c7d2879d59749c25e_1280.jpg, localUri=file:///storage/emulated/0/Pictures/AwesomeWallpapers/awesomeWallpaper-7.jpg, mediaType=image/jpeg, totalSize=172875, title=awesomeWallpaper-7.jpg, description=)
D/image_downloader( 5951): 0
D/image_downloader( 5951): RequestResult(id=5626, remoteUri=https://pixabay.com/get/57e6d344495ab108f5d084609629317e1638dde5514c704c7d2879d59749c25e_1280.jpg, localUri=file:///storage/emulated/0/Pictures/AwesomeWallpapers/awesomeWallpaper-7.jpg, mediaType=image/jpeg, totalSize=172875, title=awesomeWallpaper-7.jpg, description=)
D/image_downloader( 5951): 100
D/image_downloader( 5951): RequestResult(id=5626, remoteUri=https://pixabay.com/get/57e6d344495ab108f5d084609629317e1638dde5514c704c7d2879d59749c25e_1280.jpg, localUri=file:///storage/emulated/0/Pictures/AwesomeWallpapers/awesomeWallpaper-7.jpg, mediaType=image/jpeg, totalSize=172875, title=awesomeWallpaper-7.jpg, description=)
D/AndroidRuntime( 5951): Shutting down VM
E/AndroidRuntime( 5951): FATAL EXCEPTION: main
E/AndroidRuntime( 5951): Process: com.example.awesomewallpapers, PID: 5951
E/AndroidRuntime( 5951): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=com.example.awesomewallpapers (has extras) } in com.ko2ic.imagedownloader.Downloader$execute$1@7807408
E/AndroidRuntime( 5951):    at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1656)
E/AndroidRuntime( 5951):    at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2)
E/AndroidRuntime( 5951):    at android.os.Handler.handleCallback(Handler.java:883)
E/AndroidRuntime( 5951):    at android.os.Handler.dispatchMessage(Handler.java:100)
E/AndroidRuntime( 5951):    at android.os.Looper.loop(Looper.java:237)
E/AndroidRuntime( 5951):    at android.app.ActivityThread.main(ActivityThread.java:7811)
E/AndroidRuntime( 5951):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5951):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime( 5951):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
E/AndroidRuntime( 5951): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
E/AndroidRuntime( 5951):    at android.database.AbstractCursor.checkPosition(AbstractCursor.java:515)
E/AndroidRuntime( 5951):    at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:138)
E/AndroidRuntime( 5951):    at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:52)
E/AndroidRuntime( 5951):    at android.database.CursorWrapper.getString(CursorWrapper.java:141)
E/AndroidRuntime( 5951):    at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl.saveToDatabase(ImageDownloaderPlugin.kt:348)
E/AndroidRuntime( 5951):    at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl.access$saveToDatabase(ImageDownloaderPlugin.kt:200)
E/AndroidRuntime( 5951):    at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:301)
E/AndroidRuntime( 5951):    at com.ko2ic.imagedownloader.ImageDownloaderPlugin$CallbackImpl$granted$3.invoke(ImageDownloaderPlugin.kt:200)
E/AndroidRuntime( 5951):    at com.ko2ic.imagedownloader.Downloader.resolveDownloadStatus(Downloader.kt:171)
E/AndroidRuntime( 5951):    at com.ko2ic.imagedownloader.Downloader.access$resolveDownloadStatus(Downloader.kt:14)
E/AndroidRuntime( 5951):    at com.ko2ic.imagedownloader.Downloader$execute$1.onReceive(Downloader.kt:33)
E/AndroidRuntime( 5951):    at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1646)
E/AndroidRuntime( 5951):    ... 8 more
I/Process ( 5951): Sending signal. PID: 5951 SIG: 9
Lost connection to device.

и это мой код:

  Future<bool> downloadImage(BuildContext context, url, String user, String id) async {
    Toast.show("Downloading...", context,
        duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);

    var imageId = await ImageDownloader.downloadImage(url,
            destination: AndroidDestinationType.directoryPictures
              ..subDirectory("AwesomeWallpapers/$user$id.jpg"))
        .catchError((error) {
      if (error is PlatformException) {
        var path = "";
        if (error.code == "404") {
          print("Not Found Error.");
        } else if (error.code == "unsupported_file") {
          print("UnSupported FIle Error.");
          path = error.details["unsupported_file_path"];
        }
      }
      return false;
    });

    if (imageId != null) {
      openImage(imageId);
      return true;
    }
  }

  void openImage(var imageId) async {
    var path = await ImageDownloader.findPath(imageId);
    await ImageDownloader.open(path).catchError((error) {
      if (error is PlatformException) {
        if (error.code == "preview_error") {
          print(error.message);
        }
      }
    });
  }
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.awesomewallpapers">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"/>
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="awesomewallpapers"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

ОБНОВЛЕНИЕ Я только что заметил, что загрузка фотографий происходит с большой задержкой, и это рекурсивно вызывает некоторый код, это в отладке строки продолжали отображаться

D/image_downloader(25908): RequestResult(id=5643, remoteUri=https://pixabay.com/get/57e6d344495ab108f5d084609629317e1638dde5514c704c7d2879d59e4dc35c_1280.jpg, localUri=null, mediaType=image/jpeg, totalSize=-1, title=, description=)
D/image_downloader(25908): 0
D/image_downloader(25908): RequestResult(id=5643, remoteUri=https://pixabay.com/get/57e6d344495ab108f5d084609629317e1638dde5514c704c7d2879d59e4dc35c_1280.jpg, localUri=null, mediaType=image/jpeg, totalSize=-1, title=, description=)
D/image_downloader(25908): 0
D/image_downloader(25908): RequestResult(id=5643, remoteUri=https://pixabay.com/get/57e6d344495ab108f5d084609629317e1638dde5514c704c7d2879d59e4dc35c_1280.jpg, localUri=null, mediaType=image/jpeg, totalSize=-1, title=, description=)
D/image_downloader(25908): 0
D/image_downloader(25908): RequestResult(id=5643, remoteUri=https://pixabay.com/get/57e6d344495ab108f5d084609629317e1638dde5514c704c7d2879d59e4dc35c_1280.jpg, localUri=null, mediaType=image/jpeg, totalSize=-1, title=, description=)

, после этого приложение зависало, но не было загружено ни одной фотографии, через несколько секунд фотографии начали показываться в каталоге одна за другой!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...