I would like to make the below functionality synchronous. The "onDataLoaded" needs to be called once the stream has been read completely. Please suggest what changes needs to be done.
String JsonContent="";
new HttpClient().getUrl(Uri.parse(uri))
.then((HttpClientRequest request)
{
request.headers.removeAll(HttpHeaders.ACCEPT_ENCODING);
return request.close();
})
.then((HttpClientResponse response)
{
response.transform(UTF8.decoder).listen((contents) {
JsonContent = contents.toString();
print(JsonContent);
//onDataLoaded(JsonContent);
});
});