简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM