简体   繁体   English

尝试在 flutter 上发出获取请求时出错

[英]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."我在 makeRequests() 上收到一条错误消息,上面写着“这个 function 的返回类型为 'Future',但不以返回语句结尾。”

You must return a String in the function with the header Future< String >.您必须在 function 和 header Future<String> 中返回一个字符串。 You probably want to return response.body您可能想返回 response.body

You have to return data corresponding to the return type of the function.您必须返回与 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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 flutter 中尝试制作启动画面时出现错误 255,我该如何解决? - While trying to make splash screen with in flutter I am getting an error 255 how do I fix it? 我在尝试运行我的颤振项目时遇到错误 - I am getting error while trying to run my flutter project 我正在尝试从 API 获取数据但出现错误 - I am trying to get data from API but having error 我正在尝试制作一个 flutter 应用程序来控制我的飞利浦 Hue 灯,但我遇到了 hue_dart 问题 - I am trying to make a flutter app to control my Philips Hue lights and I'm having problems with hue_dart 您好,我在 android studio 上尝试运行我的第一个应用程序时遇到错误 - Hello i am having an error while trying to run my first app on android studio 谁能告诉我为什么我在尝试实现动画时会在 Flutter 中收到此错误 - Can anybody tell why am I getting this error in Flutter while trying to implement animation 我在颤振中收到一个调用空错误的吸气剂。 在尝试访问列表的长度时 - I am getting a getter called on null error in flutter. while trying to access the length of a list 我正在尝试制作一个测验应用程序以在 Flutter 和 Dart 中进行培训,并希望能帮助我清除以下错误 - I am trying to Make a Quiz app for training in Flutter and Dart, and would appreciate assistance in getting the following error cleared 我在尝试使用 RSS 访问数据时遇到问题 - i am having issue while trying to access data using rss 我正在尝试使用带有map_view:“ ^ 0.0.10”抖动的Google地图,但出现错误 - I am trying to use google maps with flutter with map_view: “^0.0.10” but I get an error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM