flutter_js icon indicating copy to clipboard operation
flutter_js copied to clipboard

How to make an API call?

Open devshahrukhkhan opened this issue 3 years ago • 0 comments

Need HELP!!!

Hi, I am trying to make an API call and get the data(object returned by API) in dart/flutter so that I can use the data to populate my layout. How do I do this?

what I am trying right now

  jsRuntime.evaluate("""
    console.log('evaluate');
    const fn = async () => {
      console.log('fn called');
      const response = await fetch('https://reqres.in/api/users?page=2');
      const body = await response.json();
      console.log("body ",body);
    }
    fn();
""");

In the above code evaluate and fn called print but the body never prints and if so how would I get the body in dart code? please help.

devshahrukhkhan avatar Apr 23 '22 03:04 devshahrukhkhan