I have a list of urls ending in .jpg, I am using this package: gallery_saver
(https://pub.flutter-io.cn/packages/gallery_saver)
After saving the first image, the app crashes. If there's only one image in the list then looks fine. I guess there is an issue in the async?
int downloadedImages = 0;
this.selectedImages.forEach((imageUrl) async {
await GallerySaver.saveImage(imageUrl,albumName: 'My App').then((value){
downloadedImages++;
});
});
I am not able to find any examples on how to save multiple images from the docs, any idea?
Please see the below:
I/flutter (20277): http://example.com/images/1638413558kuRlUfWDcH.jpg
I/flutter (20277): null
I/flutter (20277): http://example.com/images/1638413558eFHSBeRlF1.jpg
I/flutter (20277): null
I/flutter (20277): File size:47904
I/flutter (20277): /data/user/0/com.myapp.matrix/cache/1638413558kuRlUfWDcH.jpg
I/flutter (20277): File size:79960
I/flutter (20277): /data/user/0/com.myapp.matrix/cache/1638413558eFHSBeRlF1.jpg
E/AndroidRuntime(20277): FATAL EXCEPTION: main
E/AndroidRuntime(20277): Process: com.myapp.matrix, PID: 20277
E/AndroidRuntime(20277): java.lang.NullPointerException
E/AndroidRuntime(20277): at carnegietechnologies.gallery_saver.GallerySaver.finishWithSuccess(GallerySaver.kt:79)
E/AndroidRuntime(20277): at carnegietechnologies.gallery_saver.GallerySaver.access$finishWithSuccess(GallerySaver.kt:16)
E/AndroidRuntime(20277): at carnegietechnologies.gallery_saver.GallerySaver$saveMediaFile$1.invokeSuspend(GallerySaver.kt:74)
E/AndroidRuntime(20277): at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
E/AndroidRuntime(20277): at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
E/AndroidRuntime(20277): at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime(20277): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(20277): at android.os.Looper.loop(Looper.java:246)
E/AndroidRuntime(20277): at android.app.ActivityThread.main(ActivityThread.java:8456)
E/AndroidRuntime(20277): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(20277): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)
E/AndroidRuntime(20277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
I/Process (20277): Sending signal. PID: 20277 SIG: 9
Lost connection to device.