0

I am trying to establish connection with a server in flutter using web sockets. is there a way to listen to a response using Future and not Streams. my needed line of code is something like this :

 Future response = await ( expression to detect response from the server and return it);

does such a thing exist?

Mufasa
  • 63
  • 5

1 Answers1

0
void getFunction() async {
 var url = 'your URL';   
 late String result;
 final response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
  result = response.body;
} else {
  print('Failed');
}
return result;

You can try this out,

HeIsDying
  • 335
  • 5
  • 16