title: How to access response code and body by calling a method returning http.Response?
body: <p>I use the following class (a separate dart file) to provide API services:</p>
  <pre><code>import 'dart:convert';
  import 'package:flutter/material.dart';
  import 'package:http/http.dart' as http;
  
  class Services {
    static Future&lt;http.Response&gt; login(String username, String password) async {
      var url = &quot;https://10.0.2.2:5001/api/Login/LoginSystem&quot;;
      Map data = {&quot;Username&quot;: username, &quot;Password&quot;: password};
      var body = json.encode(data);
      var response = await http.post(Uri.parse(url),
          headers: {
            &quot;content-type&quot;: &quot;application/json&quot;,
            &quot;accept&quot;: &quot;application/json&quot;
          },
          body: body);
  
      print(response.statusCode);
      print(response.body);
      return response;
    }
  }
  </code></pre>
  <p>And I use the following code to call the service function:</p>
  <pre><code>onPressed: () {
      var response = Services.login(&quot;fa2020&quot;, &quot;123&quot;);
      if (response.statusCode == 200) {
      showDialog&lt;String&gt;(
      context: context,
      builder: (BuildContext context) =&gt;
      const AlertDialog(
          title: Text(&quot;ALert&quot;),
          content: Text(response.body),
          ));
      }
  }
  </code></pre>
  <p>My problem is that I cannot access the <code>response.statusCode</code> and <code>response.body</code> in the last code. How can I fix it?</p>