flutter_cached_network_image icon indicating copy to clipboard operation
flutter_cached_network_image copied to clipboard

Invalid argument(s): No host specified in URI

Open Khondwani opened this issue 2 years ago • 14 comments

🐛 Bug Report

Even if I put a static URL I am still getting the error below

Expected behavior

Expected behavior is that it is supposed to load the image but that is not happening

Reproduction steps

When switching to a screen that does not have cachedNetworkImage widget the error pops up

When the exception was thrown, this was the stack: #0 _HttpClient._openUrl (dart:_http/http_impl.dart:2752:9) #1 _HttpClient.openUrl (dart:_http/http_impl.dart:2623: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:97:28) #6 WebHelper._downloadOrAddToQueue (package:flutter_cache_manager/src/web/web_helper.dart:65:7) Image provider: CachedNetworkImageProvider("", scale: 1.0) Image key: CachedNetworkImageProvider("", scale: 1.0): CachedNetworkImageProvider("", scale: 1.0)

Configuration

Version: 3.3.1

Platform:

  • [ x] :iphone: iOS
  • [ x] :robot: Android

Khondwani avatar Mar 16 '24 20:03 Khondwani

I have the same problem

mazenshawky avatar Mar 17 '24 09:03 mazenshawky

I have the same problem

I resorted to using this package, they resolve this better when it comes to caching: extended_image: ^8.2.0 hope it helps you out. @mazenshawky

Khondwani avatar Mar 17 '24 09:03 Khondwani

Thanks, btw I found that this exception is caught. It doesn't affect the release mode or the flow of screens. It's just a way of informing the developer that the image didn't show.

mazenshawky avatar Mar 17 '24 10:03 mazenshawky

Yeah that I do know but I just do not like seeing that in my command line hahahaha.

Khondwani avatar Mar 17 '24 10:03 Khondwani

I have the same problem and it stops the execution of the project

abbasihamed avatar Mar 23 '24 11:03 abbasihamed

@abbasihamed try to use Android Studio or if you are using Vs Code try to use command to run the project

Pnoccio avatar Apr 22 '24 10:04 Pnoccio

The incoming URL cannot be an empty string, otherwise the above problem will occur.

xiaoweiwu avatar Jun 25 '24 07:06 xiaoweiwu

flutter: ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ flutter: The following ArgumentError was thrown resolving an image codec: flutter: Invalid argument(s): No host specified in URI flutter: flutter: When the exception was thrown, this was the stack: flutter: #0 _HttpClient._openUrl (dart:_http/http_impl.dart:2752:9) flutter: #1 _HttpClient.openUrl (dart:_http/http_impl.dart:2623:7) flutter: #2 IOClient.send (package:http/src/io_client.dart:63:38) flutter: #3 HttpFileService.get (package:flutter_cache_manager/src/web/file_service.dart:37:44) flutter: #4 WebHelper._download (package:flutter_cache_manager/src/web/web_helper.dart:115:24) flutter: #5 WebHelper._updateFile (package:flutter_cache_manager/src/web/web_helper.dart:97:28) flutter: flutter: #6 WebHelper._downloadOrAddToQueue (package:flutter_cache_manager/src/web/web_helper.dart:65:7) flutter: flutter: flutter: Image provider: CachedNetworkImageProvider("", scale: 1.0) flutter: Image key: CachedNetworkImageProvider("", scale: 1.0): flutter: CachedNetworkImageProvider("", scale: 1.0) flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════ [GETX] Info: GetImpl Instance of '_GetImpl' #0 HttpClient._openUrl (dart:_http/http_impl.dart:2752:9) #1 _HttpClient.openUrl (dart:_http/http_impl.dart:2623:7) #2 IOClient.send (package:http/src/io_client.dart:63: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:97:28) #6 WebHelper._downloadOrAddToQueue (package:flutter_cache_manager/src/web/web_helper.dart:65:7)

sajidshaikh2027 avatar Jul 10 '24 12:07 sajidshaikh2027

I work around this exception by checking the image url before passing them to the CachedNetworkImage using a simple http request:

Future<bool> validateImageUrl(String url) async {
    try {
      final response = await $http.head(Uri.parse(url));

      if (response.statusCode == 200) {
        return true;
      }
    } catch (e) {
      axlLog("Image url invalid $url");
    }

    return false;
  }

An additional step could be added to check if the Content-Type is truly an image extension.

I currently have to add this manual step at each of the API request before passing the valid URL to the UI.

nogicoder avatar Aug 12 '24 10:08 nogicoder

Thanks, btw I found that this exception is caught. It doesn't affect the release mode or the flow of screens. It's just a way of informing the developer that the image didn't show.

But if your project use Firebase Crashlytics or any crash report, the error will still reported.

sed1ka avatar Aug 14 '24 04:08 sed1ka

🐛 Bug Report

Even if I put a static URL I am still getting the error below

Expected behavior

Expected behavior is that it is supposed to load the image but that is not happening

Reproduction steps

When switching to a screen that does not have cachedNetworkImage widget the error pops up

When the exception was thrown, this was the stack: #0 _HttpClient._openUrl (dart:_http/http_impl.dart:2752:9) #1 _HttpClient.openUrl (dart:_http/http_impl.dart:2623: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:97:28) #6 WebHelper._downloadOrAddToQueue (package:flutter_cache_manager/src/web/web_helper.dart:65:7) Image provider: CachedNetworkImageProvider("", scale: 1.0) Image key: CachedNetworkImageProvider("", scale: 1.0): CachedNetworkImageProvider("", scale: 1.0)

Configuration

Version: 3.3.1

Platform:

  • [ x] 📱 iOS
  • [ x] 🤖 Android

i'have same error, but the error is the image url is '' or the image url is not right, however auther should check it better Instead of reporting an error directly.

xRuby avatar Aug 16 '24 07:08 xRuby

i think the issue arises when combining both firebase and local file i.e, i am entering a default image to display when there is no image available in my profile but when there are image saved to firebase then it works fine this type of error didn't affect the build but i cant find any solution till now

karthikps1010 avatar Aug 20 '24 06:08 karthikps1010

I managed to solve this by adding a url validation check before loading image:

final isValid = Uri.parse(image!).hasAbsolutePath;

    if (isValid) {
      return CachedNetworkImage(
        imageUrl: image ?? 'https://placehold.co/600x400',
        fit: BoxFit.cover,
        progressIndicatorBuilder: (context, url, downloadProgress) {
          return returnShimmerBasedOnImageType(downloadProgress);
        },
        errorWidget: (context, url, error) {
          return Image.asset(
            'assets/images/app_logo.png',
            fit: BoxFit.cover,
          );
        },
      );
    } else {
      return Image.asset(
        'assets/images/app_logo.png',
        fit: BoxFit.cover,
      );
    }
    ```

makis73 avatar Dec 09 '24 11:12 makis73

Still Facing Same Issue image issue, Invalid argument(s): No host specified in URI file:///,#0 _HttpClient._openUrl (dart:_http/http_impl.dart:2756:9) Although its local Images and have a validation Check

AmrTawfek avatar Dec 19 '24 10:12 AmrTawfek