'http request XMLHttpRequest error on dart / flutter

I'm trying to get some data from this Api , I got the XMLHttpRequest error even when I use this solution

import 'package:http/http.dart' as http;

void main() async {
  
  var _headers = {
    "Access-Control-Allow-Origin": "*",
    'X-API-KEY': 'SqD712P3E82xnwOAEOkGd5JZH8s9wRR24TqNFzjk'
  };
  var url = "https://api.sunnah.com/v1/collections/muslim";

  var res = await http.get(Uri.parse(url), headers:_headers);
  print(res.body);
} 


Solution 1:[1]

It'll be working fine in production mode, but you can fix it in development mode as well, I have answered this one in an another stackoverflow post.

See my answer in the link below: Flutter Web Http Error : Uncaught (in promise) Error: XMLHttpRequest error

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Prodromos Sarakinou