Baseflow / flutter_cached_network_image

Download, cache and show images in a flutter app
https://baseflow.com
2.45k stars 656 forks source link

Throws console error with some urls but all images are loaded #600

Open diegopq opened 3 years ago

diegopq commented 3 years ago

πŸ› Bug Report

I have a problem with some images, all the images are visible but in the console with some urls it throws an error and with others it does not, before it did not happen to me

Expected behavior

No error occurs when uploading images

Reproduction steps

I have a list of products each with its respective image, with this url no error occurs https://www.justpoke.club/uploads/SOPAMISO.jpg but with this one if it happens https://www.justpoke.club/uploads/EDAMAMESALVAPOR.jpg The image in both cases is shown in the application but in the case of the second image it shows me the following console error: `flutter: CacheManager: Failed to download file from with error: Invalid argument(s): No host specified in URI flutter: (debug)[2021-05-06 18:49:45.548653: ══║ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• The following ArgumentError was thrown resolving an image codec: Invalid argument(s): No host specified in URI When the exception was thrown, this was the stack:

0 _HttpClient._openUrl (dart:_http/http_impl.dart:2425:9)

1 _HttpClient.openUrl (dart:_http/http_impl.dart:2341:7)

2 IOClient.send

package:http/src/io_client.dart:30

3 HttpFileService.get

package:flutter_cache_manager/…/web/file_service.dart:35

4 WebHelper._download

package:flutter_cache_manager/…/web/web_helper.dart:114

5 WebHelper._updateFile

package:flutter_cache_manager/…/web/web_helper.dart:98

#6 WebHelper._downloadOrAddToQueue package:flutter_cache_manager/…/web/web_helper.dart:66 Image provider: CachedNetworkImageProvider("", scale: 1.0) Image key: CachedNetworkImageProvider("", scale: 1.0): CachedNetworkImageProvider("", scale: 1.0) ════════════════════════════════════════════════════════════════════════════════════════════════════] ` if I put a value to maxHeightDiskCache and maxWidthDiskCache, the error keeps happening but in different urls ### Configuration my flutter doctor is next `[βœ“] Flutter (Channel stable, 2.0.5, on macOS 11.3 20E232 darwin-x64, locale es-419) β€’ Flutter version 2.0.5 at /Users/diegopadillaquijas/fvm/versions/stable β€’ Framework revision adc687823a (hace 3 semanas), 2021-04-16 09:40:20 -0700 β€’ Engine revision b09f014e96 β€’ Dart version 2.12.3 [βœ“] Android toolchain - develop for Android devices (Android SDK version 30.0.3) β€’ Android SDK at /Users/diegopadillaquijas/Library/Android/sdk β€’ Platform android-30, build-tools 30.0.3 β€’ 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) [βœ“] VS Code (version 1.56.0) β€’ VS Code at /Applications/Visual Studio Code.app/Contents β€’ Flutter extension version 3.22.0 [βœ“] Connected device (2 available)` **Version:** 3.0.0 **Platform:** - [ x ] :iphone: iOS - [ ] :robot: Android
renefloor commented 3 years ago

Did you remove the url from the exception:

Image provider: CachedNetworkImageProvider("", scale: 1.0)

Could it be that maybe you first load an image with an empty url while you are loading the url and then reload the image again with a valid url?

diegopq commented 3 years ago

Did you remove the url from the exception:

Image provider: CachedNetworkImageProvider("", scale: 1.0)

Could it be that maybe you first load an image with an empty url while you are loading the url and then reload the image again with a valid url?

The url of the images comes together with the data of the products, it is never empty. Apparently it was solved putting a size in the property memCacheHeight and memCacheWidth. This is the widget where I use the package:

`class ProductImageCache extends StatelessWidget { final double width; final double height; final double errorWidth; final double errorHeigth; final String imageUrl; final String errorUrl; final int duration; final BoxFit imageFit; final BoxFit errorFit; final Color blendColor; final BlendMode blendMode; const ProductImageCache( {Key key, @required this.imageUrl, @required this.errorUrl, this.width, this.height, this.errorWidth, this.errorHeigth, this.duration = 1000, this.imageFit = BoxFit.contain, this.errorFit = BoxFit.contain, this.blendColor, this.blendMode}) : super(key: key);

@override Widget build(BuildContext context) { return CachedNetworkImage( imageUrl: imageUrl, fadeInDuration: Duration(milliseconds: duration), fit: imageFit, width: width, height: height, color: blendColor, colorBlendMode: blendMode, useOldImageOnUrlChange: true, memCacheHeight: 500, memCacheWidth: 500, errorWidget: (context, name, _) { return Image.asset( errorUrl, width: errorWidth, height: errorHeigth, fit: errorFit, ); }, ); } }`

ventr1x commented 3 years ago

Overall it would be great if the plugin itself can detect invalid urls and simply switch to errorWidget instead of blindly causing an exception. Right now we have to null-check every url ourselves and work with if else + duplicate the errorWidget. There are many cases, especially user generated content, which does not always have actually an image to provide (as simple as profile images). Would make the plugin way more convenient, and in any case more stable.

ragokan commented 3 years ago

image

I also have same issue, uri is defined, image is showing but I get error.

renefloor commented 3 years ago

The image you are showing, is that really the complete code and you are not using CachedNetworkImage anywhere else? The error shows you are trying to get an image from the url "undefined". Could it be that you are setting the url on a property and you are trying to show the image before that property is set?

ragokan commented 3 years ago

The image you are showing, is that really the complete code and you are not using CachedNetworkImage anywhere else? The error shows you are trying to get an image from the url "undefined". Could it be that you are setting the url on a property and you are trying to show the image before that property is set?

All the urls I am using gives error, sadly. I tried this url just to show and the url is not 'undefined'. Moreover, the image shows but I get the error.

renefloor commented 3 years ago

@ragokan I'm just trying to understand what's going on. The example app doesn't do this (right?). Could you create a simple example that you can share with me that shows the problem?

ragokan commented 3 years ago

@ragokan I'm just trying to understand what's going on. The example app doesn't do this (right?). Could you create a simple example that you can share with me that shows the problem?

Well, I think the problem is depended on something else, I created an empty app, there are no errors.

image

But for example, in this app, I just copied the image above, it is from github. image

Or, I just copied the logo of google; image

My dependencies; cached_network_image: ^3.0.0 dio: ^4.0.0 fl_chart: ^0.36.1 flutter_html: ^2.1.0 image_picker: ^0.8.1+1 intl: ^0.17.0 okito: ^1.2.0 share: ^2.0.4

renefloor commented 3 years ago

What's the CustomIndicator?

Edit: could you maybe also try your original app without the hero?

kleyos commented 3 years ago

the same issue

ragokan commented 3 years ago

What's the CustomIndicator?

Edit: could you maybe also try your original app without the hero?

the same issue

I tried it again with a clean project, I didn't get any error. I think it is because of some other packages.

aytunch commented 2 years ago

@ragokan Could you find what was the cause of the exception? It is really annoying to get this while debugging and I always get it for some reason :/

ragokan commented 2 years ago

@ragokan Could you find what was the cause of the exception? It is really annoying to get this while debugging and I always get it for some reason :/

I just upgraded all of my packages, then it suddenly go away. I don't really know what was the cause but it results from another package.

amatier2 commented 2 years ago

@ragokan Could you find what was the cause of the exception? It is really annoying to get this while debugging and I always get it for some reason :/

I just upgraded all of my packages, then it suddenly go away. I don't really know what was the cause but it results from another package.

I updated my packages and the error seemed to go away if the image URL was null but it persists if the URL is not null.

mmustafaget commented 2 years ago
======== Exception caught by image resource service ================================================
The following ArgumentError was thrown resolving an image codec:
Invalid argument(s): No host specified in URI

When the exception was thrown, this was the stack: 
#0      _HttpClient._openUrl (dart:_http/http_impl.dart:2662:9)
#1      _HttpClient.openUrl (dart:_http/http_impl.dart:2568:7)
#2      IOClient.send (package:http/src/io_client.dart:35:38)
#3      HttpFileService.get (package:flutter_cache_manager/src/web/file_service.dart:35:44)
#4      WebHelper._download (package:flutter_cache_manager/src/web/web_helper.dart:121:24)
#5      WebHelper._updateFile (package:flutter_cache_manager/src/web/web_helper.dart:103:28)
<asynchronous suspension>
#6      WebHelper._downloadOrAddToQueue (package:flutter_cache_manager/src/web/web_helper.dart:71:7)
<asynchronous suspension>
Image provider: CachedNetworkImageProvider("", scale: 1.0) 
 Image key: CachedNetworkImageProvider("", scale: 1.0): CachedNetworkImageProvider("", scale: 1.0)
====================================================================================================

@renefloor Getting this error, although Image is showing in my ui.

renefloor commented 2 years ago

@mmustafaget It looks like you are trying to load the url "", which is just an empty string. If you do see the image I'd guess you are loading some state and you first load the empty url and then you get the path and load the real image.

mmustafaget commented 2 years ago

@mmustafaget It looks like you are trying to load the url "", which is just an empty string. If you do see the image I'd guess you are loading some state and you first load the empty url and then you get the path and load the real image.

yes YOU are right, but the thing is at the time of loading the it go-to the placeholder --but it throw the warning.

abhuzz commented 2 years ago

This error generates after initializing the class and before the build context. Can not track the exact point on debugging mode

unknowenerror

.

kishangohel commented 2 years ago

@renefloor can you tell why is it giving error from src/web ?

vietdhfpt commented 2 years ago

I'm also facing the same situation when using ios side

vishalpatel1327 commented 2 years ago

image having same issue Image loaded but it log error

kobimeridor commented 2 years ago

have the same issue

user-matth commented 1 year ago

I cleaned and upgrade all my packages and seemed to work.

Try running this inside your terminal project's: flutter clean && flutter upgrade && flutter pub cache repair && flutter pub get

And now re-open your IDE and run it again.

devsideal commented 12 months ago

Getting same issue: https://github.com/Baseflow/flutter_cached_network_image/issues/821#issuecomment-1838122803

francisnnumbi commented 8 months ago

The issue here is that the url can be empty at loading then it reload with the correct url. Now, why the library cannot detect it internally and divert to errorWidget if the errorWidget is not null ?

anggaaryas commented 13 hours ago

Get same issue too, although the image is shown and i have checked if the url is not empty

======== Exception caught by image resource service ================================================
The following ArgumentError was thrown resolving an image codec:
Invalid argument(s): No host specified in URI

When the exception was thrown, this was the stack: 
#0      _HttpClient._openUrl (dart:_http/http_impl.dart:2756:9)
#1      _HttpClient.openUrl (dart:_http/http_impl.dart:2627:7)
#2      IOClient.send (package:http/src/io_client.dart:117:38)
#3      HttpFileService.get (package:flutter_cache_manager/src/web/file_service.dart:37:44)
#4      WebHelper._download (package:flutter_cache_manager/src/web/web_helper.dart:115:24)
#5      WebHelper._updateFile (package:flutter_cache_manager/src/web/web_helper.dart:96:28)
<asynchronous suspension>
#6      WebHelper._downloadOrAddToQueue (package:flutter_cache_manager/src/web/web_helper.dart:64:7)
<asynchronous suspension>
Image provider: CachedNetworkImageProvider("", scale: 1.0)
Image key: CachedNetworkImageProvider("", scale: 1.0)
    if (url.isEmpty) {
      return SizedBox(
        height: height,
        width: width,
        child: ErrrorWidget(),
      );
    }

    return CachedNetworkImage(...)