handleResponse static method

Future handleResponse(
  1. Response response
)

Implementation

static Future<dynamic> handleResponse(http.Response response) async {
  if (response.statusCode == 200) {
    if (response.headers['content-type'] == 'application/json') {
      String utf8Body = utf8.decode(response.bodyBytes);
      return json.decode(utf8Body);
    } else {
      return response.body;
    }
  } else {
    throw Exception('Failed to load data because: ${response.body}');
  }
}