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

109

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

String url = 'http://localhost:9000/user/[email protected]';

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

    return(response.body);
}
Share:
109
Admin
Author by

Admin

Updated on December 19, 2022

Comments

  • Admin
    Admin over 1 year
    String url = 'http://localhost:9000/user/[email protected]';
    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."

    • pskink
      pskink about 4 years
      return response.body;
    • Ujas Patel
      Ujas Patel about 4 years
      change var response to http.Response response.