简体   繁体   中英

I am having an error while trying to make a get request on flutter

String url = 'http://localhost:9000/user/john.doe@email.com';
Future<String> get makeRequest() async {
    var response = await http
        .get(Uri.encodeFull(url), headers: {"Accept": "application"});

         print(response.body);

}

I get an error on makeRequests() that says "This function has a return type of 'Future', but doesn't end with a return statement."

You must return a String in the function with the header Future< String >. You probably want to return response.body

You have to return data corresponding to the return type of the function.

String url = 'http://localhost:9000/user/john.doe@email.com';

Future<String> get makeRequest() async 
{
    var response = await http.get(Uri.encodeFull(url), headers: {"Accept": "application/json"});
    print(response.body);

    return(response.body);
}

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