flutterxmlhttprequestimagedownload

flutter web - download image from url, get Error: XMLHttpRequest error


i want to download image from firebase storage using the url.

here is my code

Future<void> _download(String _url) async {
    print("START DOWNLOADDD");
    final response = await http.get(Uri.parse(_url));
    print("response done");

    final imageName = path.basename(_url);
    print(imageName);

    final appDir = await path_provider.getApplicationDocumentsDirectory();
    print(appDir);

    final localPath = await path.join(appDir.path, imageName);
    print(localPath);

    final imageFile = File(localPath);
    print("imageFile done");
    await imageFile.writeAsBytes(response.bodyBytes);
    print("download");

    listDownloadPath.add(await localPath);
    setState(() {});

    print(await "END DOWNLOADDDD");

}

it works in android, but when i try it on chrome it get error when get the response.

here is the error error

is there any way that i can do to fix it? thank you


Solution

  • It is a problem that arises in part "http.get(Uri.parse(_url))"

    I think it would be good to refer to this.

    Dart/Flutter: Http request raises XMLHttpRequest error

    3- Find '--disable-extensions'

    4- Add '--disable-web-security'

    => ...

    '--disable-extensions',

    '--disable-web-security',

    ...

    And use Uri.https('urlPath', 'callPath') instead of Uri.parse(url)