Simples requisição GET a uma API Rest em flutter

Estou tentando pegar um json fazendo uma requisição a uma API, mas esta dando erro ao fazer a requisição.

Segue o código:

Future<Map> timeStamp() async {
  const request =
      "https://armariosinteligentes.com/api/v3/timestamp";
  http.Response response = await http.get(request);
  print(json.decode(response.body));
}

Este é o json da requisição

{"timestamp":1566397501}

Resposta:

Future<Map> timeStamp() async {
  final response =
  await http.get('http://armariosinteligentes.com/api/v3/timestamp');

  if (response.statusCode == 200) {
    // If server returns an OK response, parse the JSON.
    print(json.decode(response.body));
  } else {
    // If that response was not OK, throw an error.
    throw Exception('Failed to load post');
  }
}
1 curtida