How to Implement API Calls in Flutter?

后端 未结 2 869
无人及你
无人及你 2020-12-28 11:24

I want to create a weather widget app by flutter but i am finding it difficult to do so as there is limited content on flutter. So if anyone knows how to Call , share your k

2条回答
  •  抹茶落季
    2020-12-28 11:44

    It could help someone, click here for official doc

    1. Making Http Requests; import 'dart:io';
    var httpClient = new HttpClient();
    
    • Create the client.

    • Construct the Uri.

    • Invoke the operation, and await the request object. Optionally,

    • configure the headers and body of the request.

    • Close the request, and await the response.

    • Decode the response

      get() async {
         var httpClient = new HttpClient();
         var uri = new Uri.http(
        'example.com', '/path1/path2', {'param1': '42', 'param2': 'foo'});
         var request = await httpClient.getUrl(uri);
         var response = await request.close();
         var responseBody = await response.transform(UTF8.decoder).join();
         Map data = JSON.decode(responseBody);
      }
      

提交回复
热议问题