0

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

1 Answers1

0

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

  • Remove flutter_tools.stamp 1- Go to flutter\bin\cache and remove a file named: flutter_tools.stamp

  • Modify chrome.dart 2- Go to flutter\packages\flutter_tools\lib\src\web and open the file chrome.dart.

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)

develover
  • 203
  • 2
  • 5