Flutter http error when I try to use code that works in dart

Issue

I am new to flutter and I want to create app that will help me solve chemist equations, for that I created this function:

    void main() {
  String m = "H2O";
  String n = "H2O";
  parser(m, n);
}

parser(m, n) async {
  var client = Client();
  Response response = await client
      .get(Uri.parse('https://chemequations.com/ru/?s=$m+%2B+$n&ref=input'));
  var x = parse(response.body);
  print(x.getElementsByClassName("equation main-equation well")[0].text);
}

This construction works in dart really well and prints in console right result, but in flutter I wanted to use it with SetState method, but I can’t even print result in console. It throws an error:

Error: XMLHttpRequest error.

Help me please. Thanks

Solution

Error happens because I launched application in web. Just started debugging from mobile emulator and error disappeared

Answered By – aNOOBis

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.