flutter_cached_network_image icon indicating copy to clipboard operation
flutter_cached_network_image copied to clipboard

Throws console error with some urls but all images are loaded

Open diegopq opened this issue 3 years ago • 25 comments

🐛 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 <asynchronous suspension> #6 WebHelper._downloadOrAddToQueue package:flutter_cache_manager/…/web/web_helper.dart:66 <asynchronous suspension> 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

diegopq avatar May 06 '21 23:05 diegopq

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?

renefloor avatar May 07 '21 07:05 renefloor

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, ); }, ); } }`

diegopq avatar May 07 '21 18:05 diegopq

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.

ventr1x avatar May 25 '21 11:05 ventr1x

image

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

ragokan avatar Jun 25 '21 17:06 ragokan

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?

renefloor avatar Jun 29 '21 10:06 renefloor

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.

ragokan avatar Jun 30 '21 08:06 ragokan

@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?

renefloor avatar Jun 30 '21 08:06 renefloor

@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

ragokan avatar Jun 30 '21 08:06 ragokan

What's the CustomIndicator?

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

renefloor avatar Jun 30 '21 08:06 renefloor

the same issue

kleyos avatar Aug 14 '21 10:08 kleyos

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.

ragokan avatar Aug 14 '21 13:08 ragokan

@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 :/

aytunch avatar Dec 01 '21 16:12 aytunch

@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.

ragokan avatar Dec 01 '21 17:12 ragokan

@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.

amatier2 avatar Dec 03 '21 16:12 amatier2

======== 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.

mmustafaget avatar Jan 18 '22 14:01 mmustafaget

@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.

renefloor avatar Jan 19 '22 07:01 renefloor

@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.

mmustafaget avatar Jan 19 '22 14:01 mmustafaget

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

abhuzz avatar Jan 20 '22 05:01 abhuzz

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

kishangohel avatar Feb 17 '22 14:02 kishangohel

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

vietdhfpt avatar Apr 23 '22 13:04 vietdhfpt

image having same issue Image loaded but it log error

vishalpatel1327 avatar Jun 20 '22 05:06 vishalpatel1327

have the same issue

kobimeridor avatar Nov 17 '22 12:11 kobimeridor

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.

user-matth avatar Aug 08 '23 21:08 user-matth

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

devsideal avatar Dec 04 '23 09:12 devsideal

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 ?

francisnnumbi avatar Mar 24 '24 09:03 francisnnumbi