Filipe Martins
Filipe Martins

Reputation: 61

image_downloader: ^0.31.0 doesn't show error while download but it doesnt download

So, i'm trying to download a image with the url, i've tried the image_downloader package example code and it didn't show any error. The issue that i'm having is that the image isn't downloading but on the debug console doesn't say anything.

Future<void> _downloadImage(
    String url, {
    AndroidDestinationType? destination,
    bool whenError = false,
    String? outputMimeType,
  }) async {
    String? fileName;
    String? path;
    int? size;
    String? mimeType;
    try {
      String? imageId;

      if (whenError) {
        imageId = await ImageDownloader.downloadImage(url,
                outputMimeType: outputMimeType)
            .catchError((error) {
          if (error is PlatformException) {
            String? 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"];
            }
            setState(() {
              _message = error.toString();
              _path = path ?? '';
            });
          }

          print(error);
        }).timeout(Duration(seconds: 10), onTimeout: () {
          print("timeout");
          return;
        });
      } else {
        if (destination == null) {
          imageId = await ImageDownloader.downloadImage(
            url,
            outputMimeType: outputMimeType,
          );
        } else {
          imageId = await ImageDownloader.downloadImage(
            url,
            destination: destination,
            outputMimeType: outputMimeType,
          );
        }
      }

      if (imageId == null) {
        return;
      }
      fileName = await ImageDownloader.findName(imageId);
      path = await ImageDownloader.findPath(imageId);
      size = await ImageDownloader.findByteSize(imageId);
      mimeType = await ImageDownloader.findMimeType(imageId);
    } on PlatformException catch (error) {
      setState(() {
        _message = error.message ?? '';
      });
      return;
    }

    if (!mounted) return;

    setState(
      () {
        var location = Platform.isAndroid ? "Directory" : "Photo Library";
        _message = 'Saved as "$fileName" in $location.\n';
        _size = 'size:     $size';
        _mimeType = 'mimeType: $mimeType';
        _path = path ?? '';

        if (!_mimeType.contains("video")) {
          _imageFile = File(path!);
        }
        return;
      },
    );
  }

and i'm calling it like this enter image description here

and it shows this in the console enter image description here

this is the package https://pub.dev/packages/image_downloader/example

Upvotes: 0

Views: 611

Answers (1)

Developer
Developer

Reputation: 640

Images doesn't show in gallery

Check above link , it may helpful to you. You may find Image_gallery_saver too for downloading your image , And if still you go with existing package then you raise a issue with it.

Upvotes: 1

Related Questions